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
mohapatra
Messages: 24
Registered: August 2006
Location: New Jersey
Junior Member
file.txt contains
------------------
sat1 1300
sat2 2400
sat3
sat4 500

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

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

my try
-------
#!/bin/ksh

for i in `cat file.txt`
do
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
done

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
BlackSwan
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
#!/bin/ksh
while read x y
do
   #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: Thu Mar 28 03:51:06 CDT 2024