hi,
I need to merge a few files together the problem is that I have so many files that it will takes me week to get all the job done…
In fact, I wrote a script that put in a text file the name of the files that need to be merged.
foreach stn (`cat ../stnlist`)
ls *$stn.* > tmp$stn
Now I need to add to this script a part where it read each line of tmp$stn and give each filenames (lines) a variable (first one = 1, second one = 2,…). I can’t know in advance how many line I have but shouldn’t be more then 10 each time.
The variables will then be put into the following script so I would also need to be able to count the numbers of lines and also put that into a variables to ask the script to merge x number of files.
/usr/local/sac/bin/sac << endsac
r $1
m $2
m $3
…
w x$1
quit
endsac
Hope someone could help me… I’m on my master thesis and I don’t have weeks to do that…
I am not a cshell expert, but this loop reads a file a line at a time and bumps x by 1 for each line in file tmpstn:
#!/bin/csh
set x = 0
foreach line (“`cat tmpstn`”)
# increase line count by 1
@ x = ($x + 1)
echo “$line”
end
echo $x
I will leave the file reading and looping to you. This test stub builds two variables – var_1 & var_2:
#!/bin/csh
# build variable 1
set x = 1
set line=”this is line 1″
set eval var_${x}=”$line”
echo “var_1 is: ${var_1}”
# bump the variable counter
@ x = ($x + 1)
# build variable 2
set line=”this is line 2″
set eval var_${x}=”$line”
echo “var_2 is: ${var_2}”