![]() |
|
|
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 |
| Exclude Certain Entries from Piped or Redirected Output? | downplay | Shell Programming and Scripting | 1 | 02-28-2009 04:58 PM |
| Problem with assigning output of grep + awk to a variable | meheretoknow | Shell Programming and Scripting | 5 | 12-16-2008 04:50 AM |
| Assigning output of command to a variable in shell | sankar reddy | Shell Programming and Scripting | 6 | 02-28-2008 03:01 AM |
| assigning nawk output to shell variable | user_prady | Shell Programming and Scripting | 6 | 11-29-2007 04:01 AM |
| assigning command output to a shell variable | kprattip | Shell Programming and Scripting | 2 | 07-09-2007 05:01 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
assigning a multiline grep output which has been piped through sed to a shell variabl
Hi,
I wish to format the output of a grep command in such a way that sed will be able to handle the newline characters held in the output. Since sed does not allow newlines to be contained in a replacement pattern, that means adding a backslash '\' character to the end of each line from grep. Once this is done I want the correctly formatted string to be held in a shell variable so I can submit it to another sed command. For example my input file is: test line1 test line2 test line3 The result held in a shell variable like $OUT would look like: test line1\ test line2\ test line3\ The text held in $OUT would then be used as a replacement pattern in a subsequent sed command. However, regardless of what commands I use, I always get a 'command garbled' error from sed. What I've tried: From the command prompt the below works, but it is not storing the result in a shell variable: msgspb01.es.cpth.ie:/home/tim>grep test /home/tim/input.txt | sed 's/$/\\/' test line1\ test line2\ testline3\ msgspb01.es.cpth.ie:/home/tim> Now, if I try and store the result in $OUT: msgspb01.es.cpth.ie:/home/tim>OUT=`grep test /home/tim/input.txt | sed 's/$/\\/'` sed: command garbled: s/$/\/ msgspb01.es.cpth.ie:/home/tim> I get the same result if I enclose the sed command in double quotes: msgspb01.es.cpth.ie:/home/tim>OUT=`grep test /home/tim/input.txt | sed "s/$/\\/"` sed: command garbled: s/$/\/ msgspb01.es.cpth.ie:/home/tim> Note, I get the same result if I place the above commands in a /bin/sh script. Does anybody know if it is possible to store the output of grep output filtered through sed and store it in a variable? If not, How can I easily solve this problem? system details: output of uname -a: SunOS msgspb01.es.cpth.ie 5.8 Generic_117350-51 sun4u sparc SUNW,Sun-Fire-280R Though problem also occurs on linux. I'm using the standard /usr/bin/sed installed on the system. Many thanks, Tim |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|