Hi All,PHV,
Below is a script which PHV assisted me with. My question is what if the file does not constist of /^128 A/, it should exit with a print statement.
My suggestion is to getline (first line), if $0!~/ AT 1.1 LV 1.1 then exit. Check if output file is "-s" and if not true, use the rm command.
How would I be able to implement my suggestion into this scipt, or use an alternative method to do this.
awk -v opt=1or2 'BEGIN{tty="/dev/tty"}
/^128 A/{a=NR}
a&&NR==(a+opt){
printf "Line %d\n======\n%s %s : Please enter New Number-->",opt,$1,$2 >tty
if((getline reply<tty)>0){
printf "%d Before: %s\n",NR,$0 >"change.log"
$1=reply;$2=""
printf "%d After: %s\n",NR,$0 >"change.log"
}
}
{buf[NR]=$0}
END{for(i=1;i<=NR;++i)print buf}
' /path/to/input >output.txt
mv output.txt input
Many Thanks
Chris
Below is a script which PHV assisted me with. My question is what if the file does not constist of /^128 A/, it should exit with a print statement.
My suggestion is to getline (first line), if $0!~/ AT 1.1 LV 1.1 then exit. Check if output file is "-s" and if not true, use the rm command.
How would I be able to implement my suggestion into this scipt, or use an alternative method to do this.
awk -v opt=1or2 'BEGIN{tty="/dev/tty"}
/^128 A/{a=NR}
a&&NR==(a+opt){
printf "Line %d\n======\n%s %s : Please enter New Number-->",opt,$1,$2 >tty
if((getline reply<tty)>0){
printf "%d Before: %s\n",NR,$0 >"change.log"
$1=reply;$2=""
printf "%d After: %s\n",NR,$0 >"change.log"
}
}
{buf[NR]=$0}
END{for(i=1;i<=NR;++i)print buf}
' /path/to/input >output.txt
mv output.txt input
Many Thanks
Chris