Script for editing column files

Hi,

I have been doing files editing (using "vi") to change the period (e.g. 0902 to 0903) for 100 files each week as shown in the example below. I would like to have a script to solve this manual files editing. Please advice.

Example:

Change from:

HDD|0200|VIA|+000000000598.490|0000018877799204|0902|000000|

to

HDD|0200|VIA|+000000000598.490|0000018877799204|0903|000000|

Thanks :slight_smile:

#!/bin/sh
# $1 directory
# $2 first string
# $3 string replacement
#Check we have the right number of arguments
if [ $# -ne 3 ]
then
usage
else
MYDIR=$1  
echo "checking $MYDIR" #debug
for file in `ls $MYDIR/*`
do
echo "fixing $file"
echo "cp $file $file\_bak"|sed  's/\\_bak/_bak/'>tmp.sh
sh tmp.sh
echo "sed 's/$2/$3/g' $file >$file\_fix" |sed  's/\\_fix/_fix/'>tmp.sh
sh tmp.sh
echo "mv $file\_fix $file"|sed 's/\\_fix/_fix/'>tmp.sh
sh tmp.sh
done
fi

Thanks for the script...

It is working for me...