AWK: go through the file twice, doing different tasks

后端 未结 1 1784
情深已故
情深已故 2021-01-17 21:14

I am processing a fairly big collection of Tweets and I\'d like to obtain, for each tweet, its mentions (other user\'s names, prefixed with an @), if the mentio

1条回答
  •  -上瘾入骨i
    2021-01-17 21:36

    The idiomatic way to process two separate files, or the same file twice in awk is like this:

    awk 'NR==FNR{ 
        # fill associative array 
        next
    }
    {
        # use the array
    }' file1 file2
    

    The total record number NR is only equal to the record number for the current file FNR on the first file. next skips the second block for the first file. The second block is then processed for the second file. If file1 and file2 are the same file, then this passes through the file twice.

    0 讨论(0)
提交回复
热议问题