The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to build a command into a string rather than execute the command littlejon Shell Programming and Scripting 1 05-29-2008 08:05 PM
to execute the command swlist vivek_damodaran HP-UX 6 11-09-2007 05:56 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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-27-2006
sabercats sabercats is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 66
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.
  #2 (permalink)  
Old 03-27-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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..
  #3 (permalink)  
Old 03-27-2006
sabercats sabercats is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 66
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 (permalink)  
Old 03-28-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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..
  #5 (permalink)  
Old 03-28-2006
sabercats sabercats is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 66
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
  #6 (permalink)  
Old 03-28-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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?
  #7 (permalink)  
Old 03-28-2006
sabercats sabercats is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 66
Hi,

Here is what I did and it work

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

}
}'
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0