sed command
I am using this command:
sed '2i\add it where ever it is supposed to be' auto.test to insert the line at 2nd line(position) in auto.test although I can see the correct results on screen but could not see the results if I open auto.test using vi auto.test |
Re: sed command
Quote:
Resloved it!!!!!!!!!!THANKS |
Sed's output is to stdout, you need to redirect the output to a file (do not use the same filename!!!).
$ sed '2i\add' auto.test > auto.test.out $ cat auto.test.out If file is ok: $ mv auto.test.out auto.test Do not use the same name for the infile and outfile (sed 4.x has a parameter for this). Hope this helps. |
Quote:
Thank you for your reply.....now this is a inserting operation if we hard code the string in sed statement but what if I would like to change string dynamically depending on users request... I hope I am clear here....otherwise I will just repeat myself.. All I am trying is ...how can I insert a string(that can be different each time user types in) dynamically into a file....I realized that using sed command that string has to be hard coded...so I am looking to insert dynamically.... |
You need to use the appropriate quotes and escape the $:
$ THIS_LINE="Whatever you want" $ echo $THIS_LINE Whatever you want $ sed "2i\\$THIS_LINE" auto.test line 01 Whatever you want line 02 line 03 line 04 line 05 Hope this is what you wanted to know. |
Quote:
Thank you very much.. It worked but.. I tired following for dynamically substituting text: sed "s\\replace\$THIS_LINE" auto.test >auto1.test but it is not working? How can I attain dymanic substitution? |
sed "s\\replace\`echo $THIS_LINE`" auto.test >auto1.test
Cheers, Tink |
Quote:
----------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Thank you for your response.. I tired the command: sed "s\\addation\`echo $command`" auto3.test >auto4.test and got this error message: ./auto2.test: line 5: unexpected EOF while looking for matching ``' ./auto2.test: line 7: syntax error: unexpected end of file |
Sorry, I just copied your faulty line and put my
stuff into it .... thry this one Code:
sed "s/slack/`echo $THIS_LINE`/" auto3.test >auto4.test Cheers, Tink |
Here is something which may work for you...
The extra quotes are needed around the $info so sed will process a line with spaces in it. The $num should not have that problem as it is an actual line number. Code:
#!/bin/bash |
All times are GMT -5. The time now is 10:55 PM. |