![]() |
|
|
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 |
| how to execute a sh command from a csh script | bonovox | Shell Programming and Scripting | 2 | 06-25-2008 05:24 AM |
| How to build a command into a string rather than execute the command | littlejon | Shell Programming and Scripting | 1 | 05-29-2008 09:05 PM |
| shell script to execute user command | redtiger | Shell Programming and Scripting | 1 | 04-30-2008 07:53 PM |
| script execute or no execute | Kespinoza97 | Shell Programming and Scripting | 4 | 06-23-2007 10:27 AM |
| Plz Help : How to use write command to execute command on some other terminal | Aashish | UNIX for Dummies Questions & Answers | 2 | 03-03-2006 12:25 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Please help: Build a sed command and execute it in a script
I am using an array to store some data (keys e.g 47975081_1215781266128), it can be assumed that it is key to other data.
I want extract data from a file based on a couple of keys (range) and store the resulting data in a variable using the following command: sed -n '/47975081_1215781266128/,/42628155_1215781428374/p' test1.txt In my script I build a sed command and write it to a temp file using the code below: Range1="${keys[$i]}" Range2="${keys[$i+1]}" a="sed -n '/" b="/,/" c="/p'" d=" test1.txt" echo "$a$Range1$b$Range2$c$d" > temp.txt This works ok, it writes the following string to the temp file: sed -n '/08465696_1215781522540/,/70225547_1215781581748/p' test1.txt Then I grep this file and assign the contents to a variable sedcmd=$(grep sed temp.txt) However, the string that is extracted has other characters attached, the grep extracts: sed -n ''\''/08465696_1215781522540/,/70225547_1215781581748/p'\''' test1.txt It has added: ''\' before the '/08465.... and \''' after the ....48/p' Can someone please tell me why? and how I can extract exactly what is in the temp.txt file and run it. Basically, I want to build a command, run it and assign the resulting contents to an array. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|