awk + Need to print everything (all rest fields) except $1 and $2

后端 未结 7 2196
既然无缘
既然无缘 2020-12-28 19:37

I have the following file and I need to print everything except $1 and $2 by awk

File:

INFORMATION DATA 12 33          


        
7条回答
  •  盖世英雄少女心
    2020-12-28 20:12

    If Perl is an option:

    perl -lane 'splice @F,0,2; print join " ",@F' file
    

    These command-line options are used:
    -n loop around every line of the input file, do not automatically print it
    -l removes newlines before processing, and adds them back in afterwards
    -a autosplit mode – split input lines into the @F array. Defaults to splitting on whitespace
    -e execute the perl code

    splice @F,0,2 cleanly removes columns 0 and 1 from the @F array
    join " ",@F joins the elements of the @F array, using a space in-between each element

    Variation for csv input files:

    perl -F, -lane 'splice @F,0,2; print join " ",@F' file
    

    This uses the -F field separator option with a comma

提交回复
热议问题