• add file name to output file along with the line extracted

    From kishorereddyanekalla@gmail.com@21:1/5 to All on Thu Jan 26 07:54:02 2017
    Dear group,

    I am trying to extract 10th line from group of files.
    I am able to do it with

    find . -name "*.final.out" | parallel "awk 'NR ==10' {} >> result.txt"

    However, I need to add a filename in the output file for every line so that I can identify from which file the line came from.

    Any help is appreciated.

    Best,
    Kishore

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to kishorereddyanekalla@gmail.com on Thu Jan 26 16:20:40 2017
    On 2017-01-26, kishorereddyanekalla@gmail.com <kishorereddyanekalla@gmail.com> wrote:
    Dear group,

    I am trying to extract 10th line from group of files.
    I am able to do it with

    find . -name "*.final.out" | parallel "awk 'NR ==10' {} >> result.txt"

    However, I need to add a filename in the output file for every line so that I can identify from which file the line came from.

    'NR==10 { print FILENAME, $0 }'

    You are relying on these ">> result.txt" from parallel jobs being
    atomic. This is only the case if each Awk job performs its output as a
    single write() system call.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Kishore Reddy on Thu Jan 26 17:37:53 2017
    On 2017-01-26, Kishore Reddy <kishorereddyanekalla@gmail.com> wrote:
    On Thursday, 26 January 2017 10:20:43 UTC-6, Kaz Kylheku wrote:
    On 2017-01-26, kishorereddyanekalla@gmail.com <kishorereddyanekalla@gmail.com> wrote:
    Dear group,

    I am trying to extract 10th line from group of files.
    I am able to do it with

    find . -name "*.final.out" | parallel "awk 'NR ==10' {} >> result.txt"

    However, I need to add a filename in the output file for every line so that I can identify from which file the line came from.

    'NR==10 { print FILENAME, $0 }'

    You are relying on these ">> result.txt" from parallel jobs being
    atomic. This is only the case if each Awk job performs its output as a
    single write() system call.

    Got it Thanks !!!

    P.S. If that parallel logging issue is a real problem, a non-useless use
    of cat can help:

    ( echo this; awk ' ... { print that }' ) | cat >> file

    Even the command issues multiple writes (as the above example will for sure, duen to different commands being used), cat will accumulate them up and issue
    a single write when its stdin closes --- that is, if you don't go over
    cat's I/O buffer size, which is almost certainly generous enough for a
    small piece of output.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kishore Reddy@21:1/5 to Kaz Kylheku on Thu Jan 26 09:24:41 2017
    On Thursday, 26 January 2017 10:20:43 UTC-6, Kaz Kylheku wrote:
    On 2017-01-26, kishorereddyanekalla@gmail.com <kishorereddyanekalla@gmail.com> wrote:
    Dear group,

    I am trying to extract 10th line from group of files.
    I am able to do it with

    find . -name "*.final.out" | parallel "awk 'NR ==10' {} >> result.txt"

    However, I need to add a filename in the output file for every line so that I can identify from which file the line came from.

    'NR==10 { print FILENAME, $0 }'

    You are relying on these ">> result.txt" from parallel jobs being
    atomic. This is only the case if each Awk job performs its output as a
    single write() system call.

    Got it Thanks !!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)