I need to do a search/replace on a large number of files with some pretty straight-forward rules. As an example:
Original File
0110 OPEN (1)"bozo-03"
0115 REM OPEN (1,ERR=go_away)"bozo-03"
0120 OPEN (13)"dodo-04"
0200 FIND (1,KEY="BT07)IOL=8105
Desired Results
0110 OPEN (BOZO03_DEV)"bozo-03"
0115 REM OPEN (BOZO03_DEV,ERR=go_away)"bozo-03"
0120 OPEN (13)"dodo-04"
0200 FIND (BOZO03_DEV,KEY="BT07)IOL=8105
The channel number ("1" in this example) will vary. I can run the script multiple times to accomodate this. But, in general this is what I need:
Look for the OPEN (1)"bozo-03" or the alternate of OPEN (1,ERR=something)"bozo-03".
Take the filename which is within the quotes, and use that information to create a replacement for the Channel Number. The conversion would strip out the "-", uppercase the alpha characters, and append "_DEV". So
OPEN (1)"bozo-03" becomes
OPEN (BOZO03_DEV)"bozo-03"
and
OPEN (1,ERR=something)"ivmast-07" would become
OPEN (IVMAST07_DEV,ERR=something)"ivmast_07".
I have this so far to help find the lines which need to be changed:
This seems to find the strings I want to replace, but I need help using the "substr" option in awk to create the replacement string.
Ideally, I'd like to run through the list of files once for each different channel number and save the results to a different directory, where I could run some manual comparisons to verify the changes.
Any help is appreciated.
Original File
0110 OPEN (1)"bozo-03"
0115 REM OPEN (1,ERR=go_away)"bozo-03"
0120 OPEN (13)"dodo-04"
0200 FIND (1,KEY="BT07)IOL=8105
Desired Results
0110 OPEN (BOZO03_DEV)"bozo-03"
0115 REM OPEN (BOZO03_DEV,ERR=go_away)"bozo-03"
0120 OPEN (13)"dodo-04"
0200 FIND (BOZO03_DEV,KEY="BT07)IOL=8105
The channel number ("1" in this example) will vary. I can run the script multiple times to accomodate this. But, in general this is what I need:
Look for the OPEN (1)"bozo-03" or the alternate of OPEN (1,ERR=something)"bozo-03".
Take the filename which is within the quotes, and use that information to create a replacement for the Channel Number. The conversion would strip out the "-", uppercase the alpha characters, and append "_DEV". So
OPEN (1)"bozo-03" becomes
OPEN (BOZO03_DEV)"bozo-03"
and
OPEN (1,ERR=something)"ivmast-07" would become
OPEN (IVMAST07_DEV,ERR=something)"ivmast_07".
I have this so far to help find the lines which need to be changed:
Code:
file=$1
n_chan=$2
case $n_chan in
1)
dfile=`cat $file|egrep '(OPEN \(1\)|OPEN \(1,)'|awk -F \) '{print $2}'`
;;
2)
dfile=`cat $file|egrep '(OPEN \(2\)|OPEN \(2,)'|awk -F \) '{print $2}'`
;;
*)
echo "Nope"
;;
esac
echo "Found: $dfile"
Please ignore the "needless use of Cat" infraction.
Ideally, I'd like to run through the list of files once for each different channel number and save the results to a different directory, where I could run some manual comparisons to verify the changes.
Any help is appreciated.