AWK print command for specific rows

后端 未结 1 1768
感动是毒
感动是毒 2021-01-29 14:07

I have millions of records in my file, what i need to do is print columns 1396 to 1400 for specific number of rows, and if i can get this in excel or notepad.

Tried with

相关标签:
1条回答
  • 2021-01-29 14:41

    You need a condition to specify which rows to apply the action to:

    awk '<<condition goes here>> {print $1396,$1397,$1398,$1399,$1400}' file_name
    

    For example, to do this only for rows 50 to 100:

    awk 'NR >= 50 && NR <= 100 {print $1396,$1397,$1398,$1399,$1400}' file_name
    

    (Depending on what you want to do, you can also have much more complicated selection patterns than this.)

    Here's a simpler example for testing:

    awk 'NR >= 3 && NR <= 5 {print $2, $3}'
    

    If I run this on an input file containing

    1 2 3 4
    2 3 4 5
    3 a b 6
    4 c d 7
    5 e f 8
    6 7 8 9
    

    I get the output

    a b
    c d
    e f
    
    0 讨论(0)
提交回复
热议问题