Question : Change file name/extension depending on contents of first line

I'm looking for a robust way of scripting the following,
either in perl or unix shell script, for AIX

I have two files that get produced each day one will have the first line starting with 'T1I' the other will have 'T1C', i then need to rename 'T1I' to datestamp.inv and 'T1C' datestamp.crd

The datestamp is no problem but i'm not sure of the best way of doing the file extention

I was thinking of something like this,

'find . -exec grep "T1C" '{}' \; -print'

there will be more than one 'T1C' or 'T1I' but never mixed,

So i could do something like

EXT=$?
if [ $EXT > 1 ]
then
cat file > file.inv
else
cat file > file.crd
fi

But i'm not sure how to turn the find command into into a number

Answer : Change file name/extension depending on contents of first line

In that case, you can do
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
#!/bin/sh
cd /some/dir
DATE=`date +%Y%m%d`
 
if grep TC1 file >/dev/null
then
   mv file $DATE.crd
elsif grep T1I file >/dev/null
then
   mv file $DATE.inv
fi
Open in New Window Select All
Random Solutions  
 
programming4us programming4us