Hello List,
I use regex while define RS in gawk, everything is working fine except I don't know the trick to print the original RS, please see if you can help.
source:
Mon Oct line1
line2
line3
Tue Nov line4
line5
Fri Dec line6
line7
statement
gawk 'BEGIN { RS = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov)" } { print NR RS " " $0 }
output
1(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov)
2(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov) line1
line2
line3
3(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov) line4
line5
4(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov) line6
line7
desire output
1 Mon Oct line1
line2
line3
2 Tue Nov line4
line5
3 Fri Dec line6
line7
Thanks for any input.
I use regex while define RS in gawk, everything is working fine except I don't know the trick to print the original RS, please see if you can help.
source:
Mon Oct line1
line2
line3
Tue Nov line4
line5
Fri Dec line6
line7
statement
gawk 'BEGIN { RS = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov)" } { print NR RS " " $0 }
output
1(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov)
2(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov) line1
line2
line3
3(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov) line4
line5
4(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Dec|Nov) line6
line7
desire output
1 Mon Oct line1
line2
line3
2 Tue Nov line4
line5
3 Fri Dec line6
line7
Thanks for any input.