![]() |
|
|
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 |
| Redirect to a Variable? Or is it cmd cap? | oxoxo | UNIX for Dummies Questions & Answers | 2 | 11-22-2008 08:59 AM |
| redirect cat to variable | shailesh_arya | Shell Programming and Scripting | 7 | 07-10-2008 05:34 AM |
| Redirect to variable | MrAd | UNIX for Dummies Questions & Answers | 2 | 05-07-2007 05:18 PM |
| Redirect from Variable to command line?? | ugh | UNIX for Dummies Questions & Answers | 8 | 03-28-2006 11:31 AM |
| redirect command output to variable | hugow | UNIX for Dummies Questions & Answers | 1 | 06-22-2005 07:43 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
variable redirect messing up a sed command.
Not sure if that title is decent, but here we go. I'm running this string of commands: Code:
qstat -f $1 | sed 's/^[ \t]*//' | sed -n -e ":a" -e "$ s/\n//gp;N;b a" | sed 's/\\,/,/' | awk -F"PBS_O_WORKDIR=" '{print $2}' | awk -F",PBS_O_SYSTEM" '{print $1}'
In case you're curious is takes the output of a PBS queue, removes all the leading spaces, removes all the linebreaks, removes the backslash escape character in front of any commas, then grabs the output between two strings, effectively extracting a variable from a large mess of output from PBS. When I run that, it works just fine, all steps work perfectly. However, when I direct the output into a variable, the sed command to remove the backslash fails. So, I simplified the problem: echo "Hello\,World" | sed 's/\\,/,/' --> "Hello,World" var=`echo "Hello\,World" | sed 's/\\,/,/'`; echo $var --> "Hello\,World" any thoughts? |
|
||||
|
"Cascading backslashes" a.k.a "Leaning toothpicks"! ![]() Code:
var=`echo "Hello\,World" | sed 's/\\\,/,/'`; echo $var --> "Hello,World" seems to work! It's because the backticks are spawning another subshell, but the original backslashes have already been interpreted by the first one. |
![]() |
| Bookmarks |
| Tags |
| backquotes, backslashes, redirect, sed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|