China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-15 14:07
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » Who taught me how to write this? View 1,831 Replies 1
Original Poster Posted 2010-12-01 17:53 ·  中国 上海 闵行区 电信
新手上路
Credits 15
Posts 11
Joined 2009-02-19 16:51
17-year member
UID 139288
Gender Male
From 安微
Status Offline
There are numbers with 11 digits in a.txt, such as:
12345678910
58156451511
62264545655
23331561615
21215121525

I want to take 10 digits and save them to b.txt. How to write it?

Best to tell the meaning of each sentence, thank you, everyone.
Floor 2 Posted 2010-12-02 21:36 ·  中国 浙江 杭州 电信
初级用户
Credits 29
Posts 15
Joined 2010-11-24 14:33
15-year member
UID 178185
Gender Male
Status Offline

sed 's/$//g' a.txt

Replace the last digit with empty.


sed 's/\(*\)$/\1/g' a.txt

Group, the previous several digits as one group, the last digit as the second group, then use the first group to replace the whole string.



peter@ubuntu-maverick:~/temp$ cat a.txt
12345678910
58156451511
62264545655
23331561615
21215121525
peter@ubuntu-maverick:~/temp$ sed 's/\(*\)$/\1/g' a.txt
1234567891
5815645151
6226454565
2333156161
2121512152


[ Last edited by peterhuang on 2010-12-2 at 21:42 ]
Forum Jump: