Home » Infrastructure » Unix » Awk in a for loop
Awk in a for loop [message #279340] Wed, 07 November 2007 18:58 Go to next message
Messages: 24
Registered: August 2006
Location: New Jersey
Junior Member
file.txt contains
sat1 1300
sat2 2400
sat4 500

I need to write a shell script that will output like the below

sat1.ksh 1300
sat2.ksh 2400
sat4.ksh 500

my try

for i in `cat file.txt`
SCR_NAME=`echo $i| awk '{print $1}'`
PARAM=`echo $i| awk '{print $2}'`
echo "${SCR_NAME}.ksh ${PARAM}"
# want to call a function here in future

can someone please advise??
Re: Awk in a for loop [message #279341 is a reply to message #279340] Wed, 07 November 2007 19:05 Go to previous messageGo to next message
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
1) This forum is for the discussion and answering Oracle related questions; not basic shell programming
2) file extentions (.ksh) are meaningless in Unix shells
3) awk '{print $1".ksh "$2}' < file.txt > corrected.ksh
Re: Awk in a for loop [message #279342 is a reply to message #279340] Wed, 07 November 2007 19:10 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
while read x y
   #echo "$x.ksh $y"
   echo "${x}.ksh ${y}"
done < file.txt

didn't see prev post...

Try http://www.google.com/search?q=awk+one+liners

[Updated on: Wed, 07 November 2007 19:13]

Report message to a moderator

Previous Topic: Help me to unistall Oracle in Solaris 10
Next Topic: What're the patch sets of Solaris 10 do I need to install Oracle 9?
Goto Forum:

Current Time: Mon Mar 27 11:38:42 CDT 2023