Results 1 to 8 of 8
i have problem like:
sample input:
s123 s3
s32532 s88888888
s3
s56
s23@hotmail.com
abcd@hotmail.com
i need a sed script to make the output like
s00000123 s00000003
s00032532 s88888888
s00000003
s00000056
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-07-2005 #1Just Joined!
- Join Date
- Sep 2005
- Posts
- 3
sed programming
i have problem like:
sample input:
s123 s3
s32532 s88888888
s3
s56
s23@hotmail.com
abcd@hotmail.com
i need a sed script to make the output like
s00000123 s00000003
s00032532 s88888888
s00000003
s00000056
s00000023@msn.com
abcd@msn.com
it means if the work start with 's' than make it 8 digit(add 0s)
and also change the hotmail.com to msn.com
- 09-07-2005 #2Then:Code:
# foo.sed s/s/s00000000/g s/hotmail/msn/g
Code:cat input | sed -f foo.sed
- 09-07-2005 #3Just Joined!
- Join Date
- Sep 2005
- Posts
- 3
it not replace by s0000000
it is if the digit follow s not 8 digit than add 0s to make it 8 digits
- 09-07-2005 #4Linux Engineer
- Join Date
- Nov 2004
- Location
- Ft. Polk, LA
- Posts
- 796
Try reading the sed man page and doing your own homework.
- 09-07-2005 #5Well, sed is a stream editor. So it replaces things.it not replace by s0000000
In order to do this you're going to need to have a double expression to match every possibility up until eight digits. For example:
This will match a value like 's91' and turn it into 's00000091'. You will need a double expression likewise to match 's1', 's391', s'0391', etc. etc. (To break this down into little details: the first expression matches a line that starts with s and then has two digits and nothing else on the line; then it replaces it with s, a series of zeroes, and the expression it matched; then the second expression replaces the second s with nothing.)Code:sed -e 's/^s[0-9]\{2\}$/s000000&/g' -e 's/s//2' some-file
Pretty complicated, eh? Maybe sed is not the right tool for this. You should look into awk as well, and maybe python.
"When all you have is a hammer, everything looks like a nail." - as they say.
- 09-10-2005 #6Just Joined!
- Join Date
- Sep 2005
- Posts
- 3
i still got the problem in the line like:
s1 s2 s3
i can replace like
s00000001 s2 s0000003
but i can not do any thing with the s2
- 09-10-2005 #7Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Why have you chosen to use sed for this task?
- 09-10-2005 #8Linux Engineer
- Join Date
- Sep 2003
- Location
- Knoxhell, TN
- Posts
- 1,078
is this homework or are you teaching yourself out of a book?
if you're teaching yourself, re-read about count arguments to sed commands and such.
if it's homework, stop asking us to do *your* homework.Their code will be beautiful, even if their desks are buried in 3 feet of crap. - esr


Reply With Quote
