cancel
Showing results for 
Search instead for 
Did you mean: 

awk script

SOLVED
Go to solution
Asad Malik
Frequent Advisor

awk script

Hi

I have put these commands in a file named as r
date
uname ?a
uptime

and running this command
# for i in `cat r |awk -F n ?{print}?`
>do
>echo $i
>done
and the output is

date
uname
-a
uptime

and output I want is
date
uname ?a
uptime

Any help is appreciated

Thanks
4 REPLIES
RikTytgat
Honored Contributor

Re: awk script

Hi,

Before executing your for loop, do

IFS=""

and after the for loop do

unset IFS

See IFS in sh-posix(1) for descrip^tion of IFS.

Hope this helps,
Rik
RikTytgat
Honored Contributor

Re: awk script

Hi,

Or (more simple):

cat r | awk '{print}'

Bye,
Rik
Steven Sim Kok Leong
Honored Contributor
Solution

Re: awk script

Hi,

I believe the following script does what you require ie. display the commands in r in a script:
==========================
#!/sbin/sh
cat r|while read a b
do
echo $a $b # display the command in each line of file r
$a $b # execute each command along with its arguments in each line of file r
done
==========================

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
Email: steven@beepz.com. Homepage: https://www.beepz.com
Don Bentz
Regular Advisor

Re: awk script

Please forgive me for seeming dense, but what is the INTENT of this script (the "for loop", etc.)?
Insecurity is our friend. It keeps you dependent.