Replace character in files of entire folder? sed? or what?

Hello,
I do have several files in one folder each file contains measurement data.
for each file I would like to replace the character "," by "." ?

How can I do this and how can I do this for each file at once?
E.G. data_1.dat, data_x.dat (original version)
data_1out.dat, data_x_out.dat (manipulated version)!

regards
rolli

Sorry.. You want to change the filenames? or the data inside the file?

To change the data inside the files:

cd /tmp/xxx
for infile in data_?.dat; do
  prefix=`basename $infile .dat`
  outfile=${prefix}_out.dat
  tr "," "." < $infile > $outfile
done

I would like to do this :

tr "," "." < 010_DSB_DIR_187_5Hz_MODE3_1m_hor_1.dat > 010_DSB_DIR_187_5Hz_MODE3_1m_hor_1_out.dat

for all the files in the folder at once!

using your proposal:

cd /tmp/xxx for infile in data_?.dat; do   prefix=`basename $infile .dat`   outfile=${prefix}_out.dat   tr "," "." < $infile > $outfile done

doesn't work
it cannot handle theses infile outfile environment variables?
either cant read files for infile or there are ambiguous target names for outfile?

Your sample is not quite consistent - adding "out" once but "_out" the other time. If you just want the output files distinguished from the input files, try

$ awk '{gsub(",","."); print >FILENAME".out"}' *.dat

If you insist on "out" being introduced BEFORE the ".dat", try

$ awk '{gsub(",","."); fn=FILENAME; sub (".dat","out&",fn); print >fn}' *.dat
$ awk '{gsub(",","."); print >FILENAME".out"}' *.dat

this awk works fine for me but now I would like to limit the number of column
to 41?
so how can I only output line 1 to 41 to the new outfile?

regards

rolli

try using cut command

along with the awk with a pipe

cut -c1-41

it may work.
i dnt knw for sure, even i am new to unix.

line or column? How about phrasing requests carefully?

the sed works:

sed '42,$d' infile > outfile

but how to do this for all files in folder ... same question again?

---------- Post updated at 06:32 AM ---------- Previous update was at 06:31 AM ----------

line is what I desire... I was mixed up... sorry

$ awk ' FNR <= 41 {gsub(",","."); print >FILENAME".out"}' *.dat

(untested)

sed '42,$d' infile > outfile

Just a suggestion. The above is OK, but it is better in several says to just say head -n 41 infile > outfile