Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unix c shell question, fgrep and printf question

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i need to know how to in unix c shell

to printf to a file a list of variables in the form of

variable1:variable2:variable3:::

etc.

i've tried:
printf "$variable1:$variable2:$variable3:::" >> .filename

but that doesnt work, and i tried to revise many different ways and that doesnt work.

also i need to know how to search for a string in that file and just return to me the value of yes if they found a march or no no match was found.

thanks,
jada
 
Hello.

You should have post this question in the "UNIX Scripting" forum.

Try:
Code:
printf "%s:%s:%s:::\n" $var1 $var2 $var3 >> filename
or
Code:
echo "$var1:$var2:$var3:::" >> filename

and

Code:
if grep aString aFile >/dev/null; then
    echo yes
else
    echo no;
fi
 
okay , thanks i tried the printf, it works great.

i have yet to implement the fgrep utility....

with the code for the search work if i use fgrep? i need to use fixed expressions...

ex. searching for a string like "Computer Science"

thanks
 
Yes it should work with fgrep, but ... I just reread your question and it seems you use c shell and not a Bourn compatible shell.

This should work with C shell:
Code:
fgrep $aString $aFile > /dev/null
if ( $status == 0 ) then
    echo yes
else
    echo no
endif

Code:
$status
is the return status of the last commane (here the fgrep).
The return status of fgrep is 0 if a match is found (
Code:
man fgrep
).


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top