id="info"

Question

Locked

UNIX Scripting Question

By jeremy.roy ·
I'm trying to pull some text from a file using "grep", which is then saved as a variable. The variable is called, and the entire search string is translated fine, but the string itself contains other variables that are being treated as text, and not as variables. A simple example is below. Thoughts anyone? Thanks...

*********************************************
$cat 1.dat

@@001@@ STEP02
@@001@@ IF (STEP01 eq 0)
@@001@@ RUN TAKE SNODE
@@001@@ SYSOPTS="mv $file1 $file2"
@@001@@ EIF
*********************************************
$cat test.sh
#!/bin/ksh

file1=test1.txt
file2=test2.txt

the_string=`grep "@@001@@" 1.dat | sed s/@@001@@//`

echo "$the_string"
*********************************************
$test.sh
STEP02
IF (STEP01 eq 0)
RUN TAKE SNODE
SYSOPTS="mv $file1 $file2"
EIF

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

grep returns text

by psullivan In reply to UNIX Scripting Question

Grep and sed both return text, not variables. Your example shows grep & sed performing as expected. Do you want to "eval" the results of the sed or maybe pipe them into a "while ... read ..." loop? Help us understand what "other variables treated as text, and not as variables" means.

Collapse -

Could this be what you want?

by C_Tharp In reply to UNIX Scripting Question

It appears that you want the output to be like the last lines of your message. If that is so, the following script will produce it.

echo file1=test1.txt> program.sh
echo file2=test2.txt>> program.sh
grep "@@001@@" 1.dat | sed s/@@001@@// >> program.sh
more program.sh

Back to Software Forum
3 total posts (Page 1 of 1)  

Software Forums