From raj@visitnag@gmail.com to comp.lang.awk on Tue Jan 17 19:37:21 2023
From Newsgroup: comp.lang.awk
Hi
I have file with 7 fields.
The first field is serial number
In some records 5th field is missing.
Few records got truncated with the next record. In the sample file
I have shown only two records truncation but in some cases even three to four records got truncated.
sample file:
1 651 643786485 107249 5190 M SMITH 1284
2 963 212018826 103480 M746 R WADHWA 156
3 232 215036022 105012 M743 SAMBA 337
4 232 215036023 105012 M743 SAMBA 443
5 054 215036704 103325 KIYA K 351 ====> 5th field is missing
6 205 308363068 103402 5537 Mc DON 943
7 231 343328800 105880 MANO M 6403 8 231 343329128 105880 MANO M 8324 =====> in both the records 5th field is missing
9 309 361257222 103595 M564 C R SAM 102 10 309 361297561 103595 M564 C R SAM 332
11 216 308659868 625402 9693 FERNAND 365
The required output:
1 651 643786485 107249 5190 M SMITH 1284
2 963 212018826 103480 M746 R WADHWA 156
3 232 215036022 105012 M743 SAMBA 337
4 232 215036023 105012 M743 SAMBA 443
5 054 215036704 103325 4897 KIYA K 351
6 205 308363068 103402 5537 Mc DON 943
7 231 343328800 105880 MANO M 6403
8 231 343329128 105880 MANO M 8324
9 309 361257222 103595 M564 C R SAM 102
10 309 361297561 103595 M564 C R SAM 332
11 216 308659868 625402 9693 FERNAND 365
I have tried by considering the serial number as RS but did not get the desired result
awk 'BEGIN{RS="[0-9]+"}{
print $0 RT
}' file
Actually I need first four fields(including serial number) and the last field. If the "," delimiter is given in the output that would be more helpful.
Thank you
--- Synchronet 3.20a-Linux NewsLink 1.113
Who's Online
Recent Visitors
Zharous
Fri Jun 9 20:29:15 2023
from
Tempe, Az
via
Telnet
Grey Gamer
Sat Jun 10 18:23:23 2023
from
Show Low, Az
via
Telnet
Baud
Sat Jun 10 16:39:07 2023
from
Los Angeles, Ca
via
SSH
Microbot
Sat Jun 10 01:43:14 2023
from
Moore, Ok
via
Telnet