Hi All, PHV
What I need is to find a pattern 128 then count 32 lines read $2 which is 20060212092325
prompt the user to which date would he like to change to, change the date to the reply but
at the same time read reply then substr date into :
Y_R=substr(reply,1,4)
M_R=substr(reply,4,2);gsub("^0"," ",M_R)
D_R=substr(reply,7,2);gsub("^0","",D_R)
H_R=substr(reply,10,2);gsub("^0","",H_R)
M_R=substr(reply,1,2);gsub("^0","",M_R)
S_R=substr(reply,1,2);gsub("^0","",S_R)
go back 8 lines which is "2006 D" and sub {$1=Y_R;$2="D"} go to the next line "2 D" and
{$1=M_R;$2="D"} and so on until the S_R the search again
File_Example
=============
128 A
8 12301089 A
1 1 A
1 2 A
1 3 A
1 0 A
1 1 A
1 0 A
1 8 A
1 9 A
0 A
0 A
0 A
0 A
0 A
0 A
0 A
0 A
0 D
0 D
0 D
0 A
0 M
1139729005 0 D
2006 D
2 D
12 D
9 D
23 D
25 D
0 D
1 A
14 20060212092325 A
10 0000038050 A
Code from PHV
=====
awk -v opt=24 -v Num=6 -v Num2=$3 -v Num3=D 'BEGIN{tty="/dev/tty"}
/^128 A/||/^248 A/||/^129 A/{a=NR}
a&&NR==(a+opt){
printf "Line %d\n======\n%s : Please enter New Date-->",opt,$1 > tty
if((getline reply<tty)>0){
Y_R=substr(reply,1,4)
M_R=substr(reply,4,2)#;gsub("^0"," ",M_R)
D_R=substr(reply,7,2);gsub("^0","",D_R)
H_R=substr(reply,10,2);gsub("^0","",H_R)
M_R=substr(reply,1,2);gsub("^0","",M_R)
S_R=substr(reply,1,2);gsub("^0","",S_R)
if (reply){
{$1=Y_R;$2="D"};
{$1=M_R;$2=D}
{$1=D_R;$2=D}
{$1=H_R;$2=D}
{$1=M_R;$2=D}
{$1=S_R;$2=D}
{$1=slen=length(tty);$2=tty}
#printf "%d After: %s\n",NR,$0 >"change.log"
}
}
}
{buf[NR]=$0}
END{for(i=1;i<=NR;++i)print buf}
' $2 > $2.txt
Many Thanks
Chris
What I need is to find a pattern 128 then count 32 lines read $2 which is 20060212092325
prompt the user to which date would he like to change to, change the date to the reply but
at the same time read reply then substr date into :
Y_R=substr(reply,1,4)
M_R=substr(reply,4,2);gsub("^0"," ",M_R)
D_R=substr(reply,7,2);gsub("^0","",D_R)
H_R=substr(reply,10,2);gsub("^0","",H_R)
M_R=substr(reply,1,2);gsub("^0","",M_R)
S_R=substr(reply,1,2);gsub("^0","",S_R)
go back 8 lines which is "2006 D" and sub {$1=Y_R;$2="D"} go to the next line "2 D" and
{$1=M_R;$2="D"} and so on until the S_R the search again
File_Example
=============
128 A
8 12301089 A
1 1 A
1 2 A
1 3 A
1 0 A
1 1 A
1 0 A
1 8 A
1 9 A
0 A
0 A
0 A
0 A
0 A
0 A
0 A
0 A
0 D
0 D
0 D
0 A
0 M
1139729005 0 D
2006 D
2 D
12 D
9 D
23 D
25 D
0 D
1 A
14 20060212092325 A
10 0000038050 A
Code from PHV
=====
awk -v opt=24 -v Num=6 -v Num2=$3 -v Num3=D 'BEGIN{tty="/dev/tty"}
/^128 A/||/^248 A/||/^129 A/{a=NR}
a&&NR==(a+opt){
printf "Line %d\n======\n%s : Please enter New Date-->",opt,$1 > tty
if((getline reply<tty)>0){
Y_R=substr(reply,1,4)
M_R=substr(reply,4,2)#;gsub("^0"," ",M_R)
D_R=substr(reply,7,2);gsub("^0","",D_R)
H_R=substr(reply,10,2);gsub("^0","",H_R)
M_R=substr(reply,1,2);gsub("^0","",M_R)
S_R=substr(reply,1,2);gsub("^0","",S_R)
if (reply){
{$1=Y_R;$2="D"};
{$1=M_R;$2=D}
{$1=D_R;$2=D}
{$1=H_R;$2=D}
{$1=M_R;$2=D}
{$1=S_R;$2=D}
{$1=slen=length(tty);$2=tty}
#printf "%d After: %s\n",NR,$0 >"change.log"
}
}
}
{buf[NR]=$0}
END{for(i=1;i<=NR;++i)print buf}
' $2 > $2.txt
Many Thanks
Chris