doubt in sed cmd
+8
akalya
jeeva
Mahee
Maithreyi
preethika subramanian
jennyinhere
anand
Preethi
12 posters
Page 1 of 2 • 1, 2
doubt in sed cmd
- Code:
sed 's/lamb$/ham/' sed.txt
Preethi- Posts : 10
Points : 8
Join date : 2010-02-26
Re: doubt in sed cmd
[335723@oracleclient ~]$ cat sed.txt
mary had a lamb
jack ate a sapm sandwich
jill had a ham ham spamwich
[335723@oracleclient ~]$ sed 's/lamb$/ham/' sed.txt
mary had a ham
jack ate a sapm sandwich
jill had a ham ham spamwich
it works....
mary had a lamb
jack ate a sapm sandwich
jill had a ham ham spamwich
[335723@oracleclient ~]$ sed 's/lamb$/ham/' sed.txt
mary had a ham
jack ate a sapm sandwich
jill had a ham ham spamwich
it works....
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: doubt in sed cmd
I tried this. Its not working for me
jennyinhere- Posts : 24
Points : 30
Join date : 2010-02-26
Age : 35
Re: doubt in sed cmd
sed 's/a$/z/' cp.txt
hw r u
mary had a little lamb.
jill had a lamb sandwich
no change occurs in content....it doesnt work.
hw r u
mary had a little lamb.
jill had a lamb sandwich
no change occurs in content....it doesnt work.
preethika subramanian- Posts : 6
Points : 12
Join date : 2010-02-26
Re: doubt in sed cmd
$ - it changes the character or string only if it occurs at the end of d line(last word in a line)....
sed 's/u$/z/' cp.txt
hw r z
mary had a little lamb.
jill had a lamb sandwich
sed 's/u$/z/' cp.txt
hw r z
mary had a little lamb.
jill had a lamb sandwich
preethika subramanian- Posts : 6
Points : 12
Join date : 2010-02-26
Re: doubt in sed cmd
sed 'y/a/z/' dd.txt
this ll work if u try to change single character 'a' ....
''y " is used to change single char....
here a will be replaced by z....
this ll work if u try to change single character 'a' ....
''y " is used to change single char....
here a will be replaced by z....
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: doubt in sed cmd
[335818@oracleclient ~]$ sed 's/a/z/' cp.txt
hw r u
mzry had a little lamb.
jill hzd a lamb sandwich
Is this the desired output ? If so, its working
hw r u
mzry had a little lamb.
jill hzd a lamb sandwich
Is this the desired output ? If so, its working
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: doubt in sed cmd
yea ...
here s stands for substitution ....
here s stands for substitution ....
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: doubt in sed cmd
for further reference in "sed",check t topic "unix cmd doubt"....
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: doubt in sed cmd
$ to substitute if the string is in end of the line
^ to substitute if the string is in begining of the line
^ to substitute if the string is in begining of the line
Mahee- Posts : 29
Points : 233
Join date : 2010-03-03
Location : Haldia
the command 'sed' is not working all the time
the first time when i used
- Code:
sed 's/lamb$/ham/' sed.txt
Preethi- Posts : 10
Points : 8
Join date : 2010-02-26
Re: doubt in sed cmd
its workin right .. leave it..
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: doubt in sed cmd
but wats the difference in specifying it as lamb and lamb$ ??
both works
both works
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: doubt in sed cmd
[335723@oracleclient ~]$ cat aaa.txt
mlamb lambd
dhhdh dfdd
lamb lamb
ggg lambder
[335723@oracleclient ~]$ sed 's/lamb/ssss/g' aaa.txt
mssss ssssd
dhhdh dfdd
ssss ssss
ggg ssssder
[335723@oracleclient ~]$ sed 's/lamb$/ssss/g' aaa.txt
mlamb lambd
dhhdh dfdd
lamb ssss
ggg lambder
check out diff by urself...........
mlamb lambd
dhhdh dfdd
lamb lamb
ggg lambder
[335723@oracleclient ~]$ sed 's/lamb/ssss/g' aaa.txt
mssss ssssd
dhhdh dfdd
ssss ssss
ggg ssssder
[335723@oracleclient ~]$ sed 's/lamb$/ssss/g' aaa.txt
mlamb lambd
dhhdh dfdd
lamb ssss
ggg lambder
check out diff by urself...........
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: doubt in sed cmd
is it that lamb$ replaces exactly the word lamb???
if so why not the first lamb in the third line??
if so why not the first lamb in the third line??
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: doubt in sed cmd
lamb$ replaces all lines ending with lamb,whereas lamb replaces all lambs
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: doubt in sed cmd
it replaces only the lamb tat occurs as the last word in a particular line
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: doubt in sed cmd
cat > sed.txt
mlamb lambd
ddss
lamb lamb
ggg lambg
sed 's/lamb$/ham/' sed.txt
mlamb lambd
ddss
lamb ham
ggg lambg
sed 's/lamb/ham/' sed.txt
mham lambd
ddss
ham lamb
ggg hamg
sed 's/lamb/ham/g' sed.txt
mham hamd
ddss
ham ham
ggg hamg
sed 's/lamb$/ham/g' sed.txt
mlamb lambd
ddss
lamb ham
ggg lambg
these r the things that i tried out..these r all the possible combinations that i can think of..check it out...
mlamb lambd
ddss
lamb lamb
ggg lambg
sed 's/lamb$/ham/' sed.txt
mlamb lambd
ddss
lamb ham
ggg lambg
sed 's/lamb/ham/' sed.txt
mham lambd
ddss
ham lamb
ggg hamg
sed 's/lamb/ham/g' sed.txt
mham hamd
ddss
ham ham
ggg hamg
sed 's/lamb$/ham/g' sed.txt
mlamb lambd
ddss
lamb ham
ggg lambg
these r the things that i tried out..these r all the possible combinations that i can think of..check it out...
Preethi- Posts : 10
Points : 8
Join date : 2010-02-26
Re: doubt in sed cmd
[335723@oracleclient ~]$ cat aaa.txt
mlamb lambd
dhhdh dfdd
lamb lamb lamb
lamb lamb
lamb hell
ggg lambde
r
[335723@oracleclient ~]$ sed 's/lamb$/zzzz/g' aaa.txt
mlamb lambd
dhhdh dfdd
lamb lamb zzzz
lamb lamb
lamb hell
ggg lambde
r
wat abt t 4th line
mlamb lambd
dhhdh dfdd
lamb lamb lamb
lamb lamb
lamb hell
ggg lambde
r
[335723@oracleclient ~]$ sed 's/lamb$/zzzz/g' aaa.txt
mlamb lambd
dhhdh dfdd
lamb lamb zzzz
lamb lamb
lamb hell
ggg lambde
r
wat abt t 4th line
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: doubt in sed cmd
$ sed 's/lamb$/zzzz/g' aaa.txt will replace 'lamb' with 'zzzz'if a line ends with lamb.
$ sed 's/^lamb/zzzz/g' aaa.txt will replace 'lamb' with 'zzzz' if a line starts with lamb.
It is working fine. Check is there any extra space after 'lamb' in 4th line.
$ sed 's/^lamb/zzzz/g' aaa.txt will replace 'lamb' with 'zzzz' if a line starts with lamb.
It is working fine. Check is there any extra space after 'lamb' in 4th line.
Re: doubt in sed cmd
yeah it works....
and on using lamb$
even if the last word in line is "mylamb" , it ll be replaced as "myzzzz"
and on using lamb$
even if the last word in line is "mylamb" , it ll be replaced as "myzzzz"
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: doubt in sed cmd
No.... $ means it replaces the word oly wen it occurs at the end..
deepika- Posts : 3
Points : 3
Join date : 2010-03-04
Age : 36
Location : chennai
Page 1 of 2 • 1, 2
Permissions in this forum:
You cannot reply to topics in this forum
|
|