I have 30 files(ascii),which I want convert to binary.Linux command line(FORTRAN 77 CODE) that has been compiled
JavaScript
x
./rec_binary
Relevant part of the code
JavaScript
character*72 ifname,ofname
c
write(*, fmt="(/'Enter input file name')")
read(5,85) ifname
85 format(a72)
write(*, fmt="(/'Enter output file name')")
read(5,85) ofname
Then code asks for input and output file names
JavaScript
Enter input file name
rec01.txt
Enter output file name
rec.01
How to automate this?I have tried like this
JavaScript
#!/bin/csh -f
set list = 'ls rec*.txt'
foreach file ($list)
rec_binary ${file} >
Or
JavaScript
#!/bin/sh
for f in .txt
do
./rec_binary F
done
But I do not have a clue for next step.Text files are
JavaScript
rec01.txt
rec02.txt
rec30.txt
Output files
JavaScript
rec.01
rec.02
rec.30
Advertisement
Answer
Try this:
JavaScript
#!/bin/bash
for each in `ls rec*.txt`
do
op_file=$(echo $each | sed 's/(rec)([0-9]*).txt/1.2/')
./rec_binary <<EOF
$each
$op_file
EOF
done
The variable op_file
converts your rec01.txt to rec.01.