awk and execute command ???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk and execute command ???
# 8  
Old 03-28-2006
Quote:
Originally Posted by sabercats
Hi,

Here is what I did and it work

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

}
}'
congrats!
  1. UUOC
  2. tried running it on large file? You are not using 'close' for every 'system' call - you'll run out of the fd's
  3. why are you using awk for this task?
# 9  
Old 03-28-2006
MySQL

Oh I am a newbie so what make it work then I do it . I tried your code but some how I keep geting all of the file move to DATA2 instead of the files have 5 counts. Sorry for my English..

From this forum I have learned alot from you and the other.
Good site and thanks for sharing vgersh99
# 10  
Old 03-28-2006
could you post a sample of your date.txt file, pls
Also it might be a good idea to start posting using vB codes so that we get properly formated samples.
# 11  
Old 03-28-2006
Oh here is the file date.txt
20060122 20060121 1
20060214 20060122 1
20060215 20060214 1
20060216 20060215 1
20060217 20060216 1
20060220 20060217 1
20060221 20060220 3
20060222 20060221 2
20060223 20060222 1
20060224 20060223 1
20060225 20060224 1
20060226 20060225 2
20060227 20060226 2
20060228 20060227 5
20060314 20060228 2
20060315 20060314 1
20060316 20060315 1
20060317 20060316 1
20060318 20060317 1
20060319 20060318 1
20060320 20060319 2
20060321 20060320 1


and the code

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

system("mv *" $2 ".dat /DATA2/ ");

}
}'


I want to run script for
1. $testit.ksh 20060228 because it have all 5 files like A-20060228.dat, B-20060228.dat, C-20060228.dat, D-20060228.dat, E-20060228.dat

2. I want to move file with the name *-20060227.dat to /DATA2/

Last edited by sabercats; 03-28-2006 at 05:11 PM..
# 12  
Old 03-28-2006
given this script:
Code:
#!/bin/ksh


file='date.txt'

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

with 'date.txt' file being as you posted last......
I get the following 'debug' output:
Code:
testit.ksh 20060228
cp *.20060227.* /DAT2/

Is that something you're looking for?
# 13  
Old 03-28-2006
Yes, I use this script to clean up my directory and archive files Smilie . At first I get all the date of the files and sort it then uniq it to a date.txt file, then I process all of the files before 5 count, to move it out of directory, they suppose to have all 5. not 1 and 2 like I test Smilie
# 14  
Old 03-28-2006
Quote:
Originally Posted by sabercats
Yes, I use this script to clean up my directory and archive files Smilie . At first I get all the date of the files and sort it then uniq it to a date.txt file, then I process all of the files before 5 count, to move it out of directory, they suppose to have all 5. not 1 and 2 like I test Smilie
hmm.....
I'm a bit confused by the above statement, but that's ok - would not be the first time.

I guess as long as you're happy with whatever solution you're using....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

How to execute a command on each line of output from another command?

Hello :) new to bash not to programming. I have an on-going need to change the owning group on sets of files and directories from the one they were created with or changed to on update to the one they need to have going forward. find {target_root} -group wrong_group gets me a newline... (4 Replies)
Discussion started by: naftali
4 Replies

3. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

4. Shell Programming and Scripting

Execute command from awk

This seemed straight forward until I tried to code it. I'm running ioscan -fuNC disk to get list of disk including hardware path. What I'm trying to do is use awk to take this output, extract hardware path, and pass that as a variable to ioscan -P wwid -N -H 64000/0xfa00/0x1a | grep ^disk and... (11 Replies)
Discussion started by: steve72
11 Replies

5. Shell Programming and Scripting

Need help to execute command

HI, I have a directory called input directory called "input", The "input" directory contains file names (file1,file2,file3,file4), I want to write a command so that it will display all the file names with comma separated. Desired output: file1,file2,file3 so on.... Regards Akshay... (2 Replies)
Discussion started by: akshu.agni
2 Replies

6. Shell Programming and Scripting

awk and execute

Hi All, I need this to execute and not just print on Red Hat ent 4 bash shell. cat /etc/passwd|grep db2 | awk -F":" '{print "cat /etc/group | grep ",$4}' Output: cat /etc/group | grep 1000 (I don't want this to print but execute) Thanks for any comment you may add. (2 Replies)
Discussion started by: itik
2 Replies

7. UNIX for Dummies Questions & Answers

how to execute an command this way

How to make it works this way? echo dir1\/*.txt ; echo dir1\/*.html | xargs wc -l dir1/*.txt wc: dir1/*.html: No such file or directory what i'm trying to do it to "wc dir1/*.txt" and "wc dir1/*.html" (2 Replies)
Discussion started by: Bornay6ah
2 Replies

8. Shell Programming and Scripting

How to build a command into a string rather than execute the command

I'm trying to populate a command line into a variable. It appears to be executing, instead. Here's an example: mycmd='' if ...; then $mycmd='sudo ' fi $mycmd=$mycmd 'sed -i prev s/aaa/bbb/' $myfile res=`$mycmd` (I'm also not sure of the best way to execute the command from the... (1 Reply)
Discussion started by: littlejon
1 Replies

9. UNIX for Dummies Questions & Answers

Plz Help : How to use write command to execute command on some other terminal

Hi Group , I m trying to execute commands on some other system using write command but inspite of executing the commands they r passed as simple messages. - i m writing >write user-id ! ls o ctrl-d inspite of executing the command ls,other terminal shows ! ls. Thnx in advance. (2 Replies)
Discussion started by: Aashish
2 Replies

10. UNIX for Dummies Questions & Answers

How does this command execute?

Can somebody give me the explanation for this command line: ps>newfile<infile wc -l ? I am totally confused with the order of its execution.. :confused: Thanx, Saneesh Joseph. (3 Replies)
Discussion started by: saneeshjose
3 Replies
Login or Register to Ask a Question