Hi all,
I've two files, file1 and file2, which have the contents as following:
file1:
line_number_1 line_1
line_number_2 line_2
...
line_number_n line_n
file2:
line_1
line_2
..
line_m
Now, I want to add line numbers for each line in the file2, the rules are
as follows:
[1] The line numbers begin from 1, and increase naturally.
[2] If the line is also appeared in the file1, then just not use it for
numbering.
[3] If the line number also appeared in the file1, then just not use it.
For the above purpose, I write the following codes:
awk '
BEGIN { ind = 1 }
!x {
appeared_ind[$1]
appeared_line[$2]
next
}
! ($0 in appeared_line) {
while (ind in appeared_ind) ind ++
print ind, $0
ind ++
}
' file1 x=1 file2
It seems this can do my job. But my code seems not so graceful, could
you please give me some notes/hints on touching-up my above codes?
Regards
--
.: Hongyi Zhao [ hongyi.zhao AT
gmail.com ] Free as in Freedom :.