![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert Variable file to fixed file. | abhi9845 | Shell Programming and Scripting | 9 | 09-24-2008 09:07 AM |
| Convert Variable file to fixed file. | abhi9845 | UNIX for Dummies Questions & Answers | 1 | 09-15-2008 08:07 AM |
| variable in dos batch file | chssastry | Windows & DOS: Issues & Discussions | 6 | 08-29-2008 03:38 AM |
| variable into file | pppswing | Shell Programming and Scripting | 2 | 07-02-2008 05:55 AM |
| how to attach a variable from the 2nd file to the 1st file | lo tan | Shell Programming and Scripting | 5 | 06-03-2008 03:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
sed -i '7 c\$variable' file ....(?!@#$%^&*!)
I have tried everything I can think of to get sed to change line N of a file to the contents of a variable. I have Googled the Internet, and I find lots of people telling how to use variables with the "Substitute" command, but no one telling how to use variables with the "Change" command. I have considered the possibility of using the "Substitute" command with a wild card for existing text, but my search of the Internet tells me SED doesn't have wild cards in its repertoire, so it's difficult! There must be a better way. As I noted in the subject, the basic form I used is (where N is a line number): Code:
sed -i 'N c\$variable' FILE Is this possible, or is there a different command that will do it? I am working in BASH scripts. Thanks! |
|
||||
|
Yes!! It works! Thank you Franklin (and devtakh)! What an relief--better than a Christmas present!
This is really a surprise to me because I assumed the hard quote configuration was "cast in concrete". I'll have to admit, though, that my conclusions came from reading various comments during my Internet search on "sed". The manual itself is pretty vague on this subject. Now, in retrospect, I see that at the end of the manual there is reference to the sed website where the problem of variables is discussed at length! If I'd seen that in the first place, I probably could have figured it out, and not wasted the space on the Forum. But you didn't even use the "\"!!! That I wouldn't have concluded from the manual. I guess it proves how many ways there are of doing things. I'm going to go back to the sed website and do some more study. I am sure thankful for the function that "sed" provides. By the way, was I ever also wide-eyed when I found out about Zenity, after seeing it referenced on the web, and then discovered it was already installed! Amazing! Thanks again very much. Lauren. |
|
||||
|
First, -i option was not supported, so the above sed -i "N c $var " datafile is not portable.
Second, even if the -i option is not provided, using sed -i "N c[\] $var" datafile, still it cannot work. The solution might be, sed "N c\\ $var" datafile which I tested under Solaris. John, Hong p.s. sed "N s/.*/$var/" datafile also works out. Last edited by jansonx; 07-03-2009 at 07:01 AM.. Reason: I got the answer |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|