Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

doubt in sed cmd

+8
akalya
jeeva
Mahee
Maithreyi
preethika subramanian
jennyinhere
anand
Preethi
12 posters

Page 1 of 2 1, 2  Next

Go down

doubt in sed cmd Empty doubt in sed cmd

Post by Preethi Thu Mar 04, 2010 3:56 pm

Code:
sed 's/lamb$/ham/' sed.txt
this code didn work for me...y??

Preethi

Posts : 10
Points : 8
Join date : 2010-02-26

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by anand Thu Mar 04, 2010 4:01 pm

[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....
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by jennyinhere Thu Mar 04, 2010 4:08 pm

I tried this. Its not working for me

jennyinhere

Posts : 24
Points : 30
Join date : 2010-02-26
Age : 35

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by preethika subramanian Thu Mar 04, 2010 4:09 pm

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.

preethika subramanian

Posts : 6
Points : 12
Join date : 2010-02-26

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by preethika subramanian Thu Mar 04, 2010 4:14 pm

$ - 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

preethika subramanian

Posts : 6
Points : 12
Join date : 2010-02-26

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by anand Thu Mar 04, 2010 4:18 pm

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....
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by Maithreyi Thu Mar 04, 2010 4:20 pm

[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

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by anand Thu Mar 04, 2010 4:23 pm

yea ...
here s stands for substitution ....
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by anand Thu Mar 04, 2010 4:26 pm

for further reference in "sed",check t topic "unix cmd doubt"....
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by Mahee Thu Mar 04, 2010 4:35 pm

$ to substitute if the string is in end of the line
^ to substitute if the string is in begining of the line
Mahee
Mahee

Posts : 29
Points : 233
Join date : 2010-03-03
Location : Haldia

Back to top Go down

doubt in sed cmd Empty the command 'sed' is not working all the time

Post by Preethi Thu Mar 04, 2010 6:09 pm

the first time when i used
Code:
sed 's/lamb$/ham/' sed.txt
it didn work...and now its working... y s t so??

Preethi

Posts : 10
Points : 8
Join date : 2010-02-26

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by anand Thu Mar 04, 2010 6:22 pm

its workin right .. leave it..
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by jeeva Thu Mar 04, 2010 6:58 pm

but wats the difference in specifying it as lamb and lamb$ ??
both works

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by anand Thu Mar 04, 2010 7:03 pm

[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...........
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by jeeva Thu Mar 04, 2010 7:18 pm

is it that lamb$ replaces exactly the word lamb???
if so why not the first lamb in the third line??

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by Maithreyi Thu Mar 04, 2010 7:21 pm

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

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by akalya Thu Mar 04, 2010 7:22 pm

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

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by Preethi Thu Mar 04, 2010 7:24 pm

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...

Preethi

Posts : 10
Points : 8
Join date : 2010-02-26

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by anand Thu Mar 04, 2010 7:27 pm

[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
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by Christopher Thu Mar 04, 2010 11:34 pm

$ 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.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by Christopher Fri Mar 05, 2010 1:46 pm

@anand
did u try??
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by anand Fri Mar 05, 2010 4:05 pm

yeah it works....
and on using lamb$
even if the last word in line is "mylamb" , it ll be replaced as "myzzzz"
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by deepika Mon Mar 08, 2010 5:03 pm

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

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by Naveen Mon Mar 08, 2010 5:12 pm

yup...

Naveen

Posts : 15
Points : 21
Join date : 2010-03-05
Age : 35

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by Christopher Mon Mar 08, 2010 5:36 pm

@deepika

anand also trying to say the same.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

doubt in sed cmd Empty Re: doubt in sed cmd

Post by Sponsored content


Sponsored content


Back to top Go down

Page 1 of 2 1, 2  Next

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum