Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What if pattern does not exis?

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top