I am trying to print lines from a file in the format
line (a), line (a + (# of lines in file)/2).
Example file shown below (MAC addresses followed by switch port numbers for the curious, pulled from an snmpwalk). First MAC adrs (line 1 in this case) goes with first port (line 9) and so on...
"1e 47 29 00 A0 60 "
"1e 47 29 00 A0 64 "
"1e 47 29 00 A0 AF "
"1e 47 29 00 B1 50 "
"0C 72 0A 27 5F 71 "
"0C 72 0A 27 BC BA "
"2B 07 D4 A2 30 CD "
"2B 07 D4 A2 33 64 "
9
3
7
1
4
2
10
8
I know how to concatenate lines with awk thanks to the fine people on this forum, e.g.
concatenate every 5 lines of input, using a comma separator between fields
awk 'ORS=NR%5?",":"\n"' file
I'm trying to get a handle on how to use awk with NR or NF to print in the required format but I can't quite figure out how to hand awk the (a + (number of lines in file)/2) variable using possibly NF or NR.
Also, have tried writing the file to an array but my awk array skills need some serious work. And placing the two halves (MAC adrs and port) in two separate files and thence two separate arrays definitely stretched those skills - and still didn't work.
I am not tied to an awk solution - awk was just a starting point for me. A sed or perl script would be perfectly acceptable. Learning is good!
Thanks in advance!
maurie
line (a), line (a + (# of lines in file)/2).
Example file shown below (MAC addresses followed by switch port numbers for the curious, pulled from an snmpwalk). First MAC adrs (line 1 in this case) goes with first port (line 9) and so on...
"1e 47 29 00 A0 60 "
"1e 47 29 00 A0 64 "
"1e 47 29 00 A0 AF "
"1e 47 29 00 B1 50 "
"0C 72 0A 27 5F 71 "
"0C 72 0A 27 BC BA "
"2B 07 D4 A2 30 CD "
"2B 07 D4 A2 33 64 "
9
3
7
1
4
2
10
8
I know how to concatenate lines with awk thanks to the fine people on this forum, e.g.
concatenate every 5 lines of input, using a comma separator between fields
awk 'ORS=NR%5?",":"\n"' file
I'm trying to get a handle on how to use awk with NR or NF to print in the required format but I can't quite figure out how to hand awk the (a + (number of lines in file)/2) variable using possibly NF or NR.
Also, have tried writing the file to an array but my awk array skills need some serious work. And placing the two halves (MAC adrs and port) in two separate files and thence two separate arrays definitely stretched those skills - and still didn't work.
I am not tied to an awk solution - awk was just a starting point for me. A sed or perl script would be perfectly acceptable. Learning is good!
Thanks in advance!
maurie