Automatically select records from several files and then run a C executable file inside the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automatically select records from several files and then run a C executable file inside the script
# 1  
Old 11-09-2009
Automatically select records from several files and then run a C executable file inside the script

Dear list
its my first post and i would like to greet everyone
What i would like to do is select records 7 and 11 from each files in a folder then run an executable inside the script for the selected parameters.


The file format is something like this
7 100 200
7 100 250
7 100 300
7 100 400
7 100 500
7 100 700
7 100 850
7 100 925
7 100 1000
. . .
. . .
. . .
11 100 200
11 100 250
11 100 300
11 100 400
11 100 500
11 100 700
11 100 850
11 100 925
11 100 1000

i have created the following script but it gives me errors when i try to execute it

Code:
#SOURCE DIR input files
FILES= "/root/Desktop/c_command/DATA/"
# set output dir destination files
OUTPUT= /root/Desktop/c_command/OUT
# create output dir if not exists 
[ ! -d ${OUT} ] && mkdir -p ${OUT}
# full path to cnvgrib.x 
DEGRIB= "/root/Desktop/c_command/degrib.x"
cd "${FILES}"
for i in `ls`
do
echo "Processing $i grib files..."
./$DEGRIB $i $OUT/$i.txt  7 100 200 
./$DEGRIB $i $OUT/$i.txt  7 100 250 
./$DEGRIB $i $OUT/$i.txt  7 100 300 
./$DEGRIB $i $OUT/$i.txt  7 100 400 
./$DEGRIB $i $OUT/$i.txt  7 100 500 
./$DEGRIB $i $OUT/$i.txt  7 100 700 
./$DEGRIB $i $OUT/$i.txt   7 100 850 
./$DEGRIB $i $OUT/$i.txt 7 100 925 
./$DEGRIB $i $OUT/$i.txt 7 100 1000 
./$DEGRIB $i $OUT/$i.txt 11 100 200 
./$DEGRIB $i $OUT/$i.txt 11 100 250 
./$DEGRIB $i $OUT/$i.txt 11 100 300 
./$DEGRIB $i $OUT/$i.txt  11 100 400 
./$DEGRIB $i $OUT/$i.txt  11 100 500 
./$DEGRIB $i $OUT/$i.txt  11 100 700 
./$DEGRIB $i $OUT/$i.txt  11 100 850 
./$DEGRIB $i $OUT/$i.txt  11 100 925
./$DEGRIB $i $OUT/$i.txt 11 100 1000
done

Thanks in advance for your time reading the post any help will be kindly appreciated

Last edited by pludi; 11-10-2009 at 02:07 AM.. Reason: code tags, please...
# 2  
Old 11-09-2009
guess you want to get the result as below?

Change the parts:

Code:
for i in `ls`
do
echo "Processing $i grib files..."
......
done

to

Code:
for i in `ls`
do
   for j in `awk '/^7/ || /^11/ {print}' $i`
   do
       ./$DEGRIB $i $OUT/$i.txt $j
   done
do

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Quick way to select many records from a large file

I have a file, named records.txt, containing large number of records, around 0.5 million records in format below: 28433005 1 1 3 2 2 2 2 2 2 2 2 2 2 2 28433004 0 2 3 2 2 2 2 2 2 1 2 2 2 2 ... Another file is a key file, named key.txt, which is the list of some numbers in the first column of... (5 Replies)
Discussion started by: zenongz
5 Replies

2. Shell Programming and Scripting

Block of records to select from a file

Hello: I am new to shell script programming. Now I would like to select specific records block from a file. For example, current file "xyz.txt" is containing 1million records and want to select the block of records from line number 50000 to 100000 and save into a file. Can anyone suggest me how... (3 Replies)
Discussion started by: nvkuriseti
3 Replies

3. Shell Programming and Scripting

script run when executable is launched

I need to know how to have a BASH script run every time Firefox is launched, what is the simplest way to do this? (1 Reply)
Discussion started by: glev2005
1 Replies

4. Shell Programming and Scripting

How to run a script automatically

Hi All, How can i run a script every week automatically. Thanks & regards, Sam (5 Replies)
Discussion started by: sam25
5 Replies

5. Shell Programming and Scripting

run and make an executable file

as i said before i'm a beginner in shell programming and i have two questions: how to run an executable file in shell scripts like for example let's say the file called "prog.exe", what's the shell command to run this file? also how can i make the shell file an executable file (if it is... (5 Replies)
Discussion started by: _-_shadow_-_
5 Replies

6. Shell Programming and Scripting

how to run shell script automatically

hi , i m trying to run bash scrip automaticially but i dont know how i can do this an anybody tell me how i can autorun shell script when i logon . thanks (9 Replies)
Discussion started by: tahir23
9 Replies

7. UNIX for Dummies Questions & Answers

how to run a Script automatically

How to make a script run automatically using a cron?? i do not know abt cron...... if i have simple.sh file and i need this to run everyday at a particular time what needs to be done thanks in advance (4 Replies)
Discussion started by: hamsa
4 Replies

8. Shell Programming and Scripting

calling a C executable from inside a Perl script

here's the Perl code snippet... how can i call my C executable 'porter-stemmer' and pass it $1 as an argument? Thanks for the help! # Read through the original topic set, and modify based on the current # pre-processing options while (<TOPIC_ORIG>) { # Run pre-processing over only the... (3 Replies)
Discussion started by: mark_nsx
3 Replies

9. UNIX for Dummies Questions & Answers

How to run a script automatically ?????

Hi All, How to run a script automatically using cronjob everyday from Monday to Friday 9A.M to 5P.M at an interval of ONE HOUR.I want the complete syntax means how to put in the cron job and there after. URGENTLY NEED HELP THANKS IN ADVANCE CHEERS Arunava (7 Replies)
Discussion started by: arunava_maity
7 Replies
Login or Register to Ask a Question