How to print third column to last column?

前端 未结 19 2076
面向向阳花
面向向阳花 2020-11-28 18:44

I\'m trying to remove the first two columns (of which I\'m not interested in) from a DbgView log file. I can\'t seem to find an example that prints from column 3 onwards unt

19条回答
  •  再見小時候
    2020-11-28 19:03

    Perl solution:

    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 every line

    • -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

    If your input file is comma-delimited, rather than space-delimited, use -F, -lane


    Python solution:

    python -c "import sys;[sys.stdout.write(' '.join(line.split()[2:]) + '\n') for line in sys.stdin]" < file

提交回复
热议问题