File renaming with date timestamp

Hi,

This is my script:

#! /usr/bin/ksh
cd /app/chdata/workflow/suppl/esoutput/spd/testing
for file in /app/chdata/workflow/suppl/esoutput/spd/testing
do
sort *.txt | awk '{ file=substr($0,1,2)".txt"; print >> file }'
mv *.txt file_`date +"%Y%m%d%H%M%S"`.txt
done

Here, I am trying to rename all the files say *.txt to *_date.txt.

However, Its throwing an error.

Please help.

Regards,
Sunitha

what error ?

  • nilesh

You probably mean

for file in *.txt; do
  mv "$file" file_`date +"%Y%m%d%H%M%S"`.txt
done

The sort | awk seems to be entirely unrelated to this problem. It should not be inside the for loop if you don't really mean for it to also operate on each file in *.txt separately (then similarly using "$file" as the argument to sort instead of *.txt).

Thanks for the reply