awk and execute command ??? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

awk and execute command ???

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-27-2006
sabercats sabercats is offline
Registered User
 
Join Date: Feb 2006
Last Activity: 7 March 2014, 3:13 AM EST
Posts: 126
Thanks: 0
Thanked 0 Times in 0 Posts
awk and execute command ???

If I have a flat file date.txt separate by a tab

date1 date2 count
20060226 20060225 2

20060227 20060226 2

20060228 20060227 5

20060314 20060228 2

20060315 20060314 1

If $3 (count) is 5 then execute the script testit.ksh with $1=20060228 , using script testit.ksh 20060228
and if $3 is 5 then $2=20060227 and move files *.20060227.* to /DAT2/


cat date.txt |
awk '{
if ($3 == 5) {
./testit.ksh $1 ????
mv *.$2.* /DAT2/


}
}'


This is a stupid code but I just want to learn what you do with awk and command .
Thanks for teaching me.
Sponsored Links
    #2  
Old 03-27-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 19 December 2014, 6:13 PM EST
Location: Foxborough, MA
Posts: 7,679
Thanks: 156
Thanked 591 Times in 555 Posts
wouldn't it be easier to do it all in ksh?

not tested.......

Code:
#!/bin/ksh

while read d1 d2 cnt
do
    (( cnt = 5 )) && (( d1 == 20060228 )) && testit.ksh "${d1}"
    (( cnt = 5 )) && (( d2 == 20060227 )) && cp *.${d2}.* /DAT2/
done < myFile.txt


Last edited by vgersh99; 03-28-2006 at 11:18 AM..
Sponsored Links
    #3  
Old 03-27-2006
sabercats sabercats is offline
Registered User
 
Join Date: Feb 2006
Last Activity: 7 March 2014, 3:13 AM EST
Posts: 126
Thanks: 0
Thanked 0 Times in 0 Posts
I use awk because I want to findout $3 is 5, then take $1 and $2, I really dont know what will be $1 and $2 .Just use it to move or execute another script
    #4  
Old 03-28-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 19 December 2014, 6:13 PM EST
Location: Foxborough, MA
Posts: 7,679
Thanks: 156
Thanked 591 Times in 555 Posts
Quote:
Originally Posted by sabercats
I use awk because I want to findout $3 is 5, then take $1 and $2, I really dont know what will be $1 and $2 .Just use it to move or execute another script
ok. what's your point?
have looked at/tried the posted suggestion?

Last edited by vgersh99; 03-28-2006 at 12:31 PM..
Sponsored Links
    #5  
Old 03-28-2006
sabercats sabercats is offline
Registered User
 
Join Date: Feb 2006
Last Activity: 7 March 2014, 3:13 AM EST
Posts: 126
Thanks: 0
Thanked 0 Times in 0 Posts
Hi vgersh99,
Because this myFile.txt have along list and I am sure it have cnt is = 5, then take that $1 is d1 at $2 is d2. So I update your code like this but it copy every thing to DATA2 directory and somehow it can not execute the testit.ksh. Any idea ?


#!/bin/ksh

while read d1 d2 cnt
do
(( cnt = 5 )) && testit.ksh "${d1}"
(( cnt = 5 )) && cp *.${d2}.* /DAT2/
done < myFile.txt
Sponsored Links
    #6  
Old 03-28-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 19 December 2014, 6:13 PM EST
Location: Foxborough, MA
Posts: 7,679
Thanks: 156
Thanked 591 Times in 555 Posts
Quote:
Originally Posted by sabercats
Hi vgersh99,
Because this myFile.txt have along list and I am sure it have cnt is = 5, then take that $1 is d1 at $2 is d2. So I update your code like this but it copy every thing to DATA2 directory and somehow it can not execute the testit.ksh. Any idea ?


#!/bin/ksh

while read d1 d2 cnt
do
(( cnt = 5 )) && testit.ksh "${d1}"
(( cnt = 5 )) && cp *.${d2}.* /DAT2/
done < myFile.txt
could you post a sample 'myFile.txt', pls

also is your 'testit.ksh' has the 'execute' bit turned on?
Sponsored Links
    #7  
Old 03-28-2006
sabercats sabercats is offline
Registered User
 
Join Date: Feb 2006
Last Activity: 7 March 2014, 3:13 AM EST
Posts: 126
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

Here is what I did and it work

cat date.txt |
awk '{
if ($3 == 5) {
system("testit.ksh " $1);
system("mv *" $2 ".* " "/DATA2/ ");

}
}'
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to execute an command this way Bornay6ah UNIX for Dummies Questions & Answers 2 10-04-2008 05:44 PM
How to build a command into a string rather than execute the command littlejon Shell Programming and Scripting 1 05-29-2008 09:05 PM
Plz Help : How to use write command to execute command on some other terminal Aashish UNIX for Dummies Questions & Answers 2 03-03-2006 12:25 PM
How does this command execute? saneeshjose UNIX for Dummies Questions & Answers 3 01-03-2006 10:46 AM
execute command neer45 Shell Programming and Scripting 2 11-25-2001 08:45 AM



All times are GMT -4. The time now is 08:49 PM.