Hi,
I have to perform an iterative function on a set of 10 files. After the first round the output files are named differently than the input files.
examples
input file name = xxxx1.yyy
output file name = xxxx1_0001.yyy
I need to rename all of the output files to the original input name for reprocessing.
I have created two text files using ----
ls > output.txt
ls > input.txt
Now what I would like to do is assign line one of output to say $1 and input to $2 and then use the shell command
cp $1 $2
where the file listed on the first line of output.txt is cp to the file name givin in the first line of input.txt
and for this to be done for each line of the two files.
I have been trying to use an awk script
#!/usr/bin/awk -f
{d=$0}
{print d }
but I cannot figure out how to assign input file to "d" and output to "e" to then pass those variables to the shell cp command.
can anyone help me? and yes as you probably can tell, I'm very new at this.
Hi,
if your filenames differ only in the _0001 part, i would suggest
for i in *yyy; do mv $i ${i//_*./.}; done
HTH Chris
joeyg
December 1, 2008, 5:07pm
3
Helping with your awk statement, take a look at the following:
> ls file7*
file70 file71 file73 file73.n file74 file75 file77 file78 file79
> ls file7* | awk 'd=$0 {print d}'
file70
file71
file73
file73.n
file74
file75
file77
file78
file79
However, I think you would be better off with a loop like the following:
> ls file7* >list7
> while read filename; do echo $filename ; done <list7
file70
file71
file73
file73.n
file74
file75
file77
file78
file79
Instead of an echo command, you could do your rename of the file.
Thanks....yes...the names are somewhat more complex...I should have listed them as:
xxxx1.yyy
zzzz1_0001.yyy
Thanks for you reply
joeyg
December 1, 2008, 5:26pm
5
The following example
shows files that start file7
creates a file, by using awk, containing current names and desired new names
shows that work file
reads through the work file, copying from original to new names
shows that the files were just created
> ls file7*
file70 file71 file73 file74 file75 file77 file78 file79
> ls file7* | awk 'd=$0 {print d" "substr(d,1,4)"new"substr(d,5,2)}' >list7
> cat list7
file70 filenew70
file71 filenew71
file73 filenew73
file74 filenew74
file75 filenew75
file77 filenew77
file78 filenew78
file79 filenew79
> while read file1 file2; do cp $file1 $file2; done <list7
> ls filenew*
filenew70 filenew71 filenew73 filenew74 filenew75 filenew77 filenew78 filenew79
that should work fine..Thanks. Can you explain to me what the substr (d,1,4) and substr (d,5,2) do? I understand they are placing a substring of d into the name but can't figure out the number designation. Thanks!!