![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| Insert Text at begining of file | netwolf | High Level Programming | 3 | 05-27-2008 12:20 PM |
| How to insert text in the middle of a file | kartikkumar84@g | UNIX for Dummies Questions & Answers | 6 | 05-10-2008 02:35 PM |
| insert some text to a file log | bucci | Shell Programming and Scripting | 4 | 05-09-2007 07:19 AM |
| insert text into top of file | jimbob | Shell Programming and Scripting | 1 | 09-22-2006 05:46 PM |
| insert text into a dinamic file | sunbird | UNIX for Dummies Questions & Answers | 2 | 11-05-2001 10:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I had a play with this and it's all about the quotes/double quotes to make the variable expand correctly. This works in bash...
FILENAME=input_file NEWFILENAME=output_file sed '$a\ PR_DbConfigEnd '"${FILENAME}"' ' $FILENAME > $NEWFILENAME Notice to make the variable expand I used '"${FILENAME}"' That's single, double ${FILENAME} double, single. Try that. |
|
||||
|
Hos does this work..the double backslash. I've tried numerous combinations in bash, ksh and sh. But still the only way was as i suggested above. i couldn't get it working with the \\.
Can you post the rest...i.e so I can see how the quotes etc should work around the variable in the sed text. i.e. FILENAME=input_file NEWFILENAME=output_file sed '$a\ PR_DbConfigEnd '"${FILENAME}"' ' $FILENAME > $NEWFILENAME |
|
||||
|
Got that now..I wasn't getting the backslash before the $a.
So it is working. The only reason for putting the filename in the quotes as I did was that it was the only way I could get the end result to work. So Both actually acheive teh same result now..although I coulnn't explain why mine does! your on the other hand I do understand. |
|
|||||
|
Quote:
Inside single quotes, what you see is what you get. No character has any special meaning inside single quotes. So variables won't expand. A string like: '$a' will just be $a. The shell will not try to substitute the value of a variable called a. So in the line: sed '$a\ we get exactly what we ask for. Inside single quotes, even the backslash is just another character. (And, btw, this means that there is no way to get a single quote inside single quotes...so 'you can't do that' won't work and there is no way to fix it with backslashes.) When you want to use a variable inside single quotes, it won't work: 'something $var something' isn't going to do it. So we must break that single quoted string into two single quoted string and put the variable between them: 'something '$var' something' is actually good enough, but most folks will add {} whenever a variable touches non-blanks, not just other letters: 'something '${var}' something' And finally, if the value of var has a string of blanks, we would need to protect them, so we would need single quotes around the variable: 'something '"${var}"' something' And this get us to the syntax that you used. Your first single quoted string started on one line and finished on the next but otherwise it's pretty much what we have here. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|