Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
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.