|
|||||||||
| Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here. |
learn linux and unix commands - unix shell scripting |
| Tags |
| sed |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Pass variable to sed?
Hi there. If variables are named inside of a ksh script, how is it possible to pass these to sed? The affected portion of my script goes something like this: Code:
A=`cut -d. -f1 $FILE` B=`cut -d. -f2 $FILE` C=`cut -d. -f3 $FILE` sed 's/1111/$A/g;s/2222/$B/g;s/3333/$C/g' file > anotherfile now, I understand that the single quote prevents the shell from interpreting special characters, but if I omit it, the process just hangs there. Thanks, kristy (working with Solaris) Last edited by Yogesh Sawant; 10-19-2010 at 08:21 AM.. Reason: added code tags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Re: Pass variable to sed?
Take the variables out of the single quotes... Code:
sed 's/1111/'${A}'/g;s/2222/'${B}'/g;s/3333/'${C}'/g' file > anotherfileAt least that should always work. For the example you posted, it looks like double quotes would've worked. If the contents of the variables are funky, you may need double quotes around them. IE change ${A} above to "${A}" Last edited by Yogesh Sawant; 10-19-2010 at 08:21 AM.. Reason: added code tags |
| The Following 2 Users Say Thank You to Perderabo For This Useful Post: | ||
chrisjbell (12-13-2012), kalak (11-08-2011) | ||
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Worked great! Thanks for the tip.
|
| Sponsored Links | ||
|
|
![]() |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to pass value of pwd as variable in SED to replace variable in a script file | cielle | Red Hat | 6 | 03-28-2012 03:47 AM |
| How to pass a function with a variable parameter into another variable? | U_C_Dispatj | Shell Programming and Scripting | 2 | 05-26-2011 12:44 PM |
| ksh variable pass to awk | meman1188 | Shell Programming and Scripting | 4 | 05-10-2009 01:30 AM |
| How do I pass a variable to awk? | eja | UNIX for Dummies Questions & Answers | 12 | 04-03-2007 06:46 PM |
| How to pass a variable to Awk ? | Raynon | Shell Programming and Scripting | 24 | 02-26-2007 09:25 AM |
|
|