Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirect

Status
Not open for further replies.

ovince

Programmer
Feb 27, 2007
55
FR
Hi,

I would like to do the same thing to many files and to put result into files that that has the same name as input files but with different suffixes. For example if I have datafiles like

boxHUN.dat
boxDNK.dat
boxCHY.dat

the result should be writen into

boxHUN.txt
boxDNK.txt
boxCHY.txt

I started like:

ls box*.dat | xargs awk 'BEGIN {FS=","}{print $2, $3/2}' > xargs".txt"

Of course, this does not work (I thought it would). How to redirect data properly?

thanks
oliver

 
How about
for file in `ls box*.dat`
do
xargs awk 'BEGIN{FS=","}{print $2, $3/2}' > $file.txt
done
 
well I get error message like:

bash: $file.txt: ambiguous redirect

by using:

for file in `ls box*.dat`
do
xargs awk 'BEGIN{FS=","}{print $2, $3/2}' > $file.txt
done

Beside, If the input file is 'boxHUN.dat' then $file.txt writes out 'boxHUN.dat.txt' doesn't it?
 
Try this:

for file in `ls box*.dat`
do
ofile="$(basename $file .dat).txt"
awk '...' $file >$ofile
done

You have to substitute your awk program for the '...'

Note xargs is of no use here, because the for loop is processing the files one by one anyway.


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top