How to print third column to last column?

前端 未结 19 2111
面向向阳花
面向向阳花 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 18:59

    The following awk command prints the last N fields of each line and at the end of the line prints a new line character:

    awk '{for( i=6; i<=NF; i++ ){printf( "%s ", $i )}; printf( "\n"); }'
    

    Find below an example that lists the content of the /usr/bin directory and then holds the last 3 lines and then prints the last 4 columns of each line using awk:

    $ ls -ltr /usr/bin/ | tail -3
    -rwxr-xr-x 1 root root       14736 Jan 14  2014 bcomps
    -rwxr-xr-x 1 root root       10480 Jan 14  2014 acyclic
    -rwxr-xr-x 1 root root    35868448 May 22  2014 skype
    
    $ ls -ltr /usr/bin/ | tail -3 | awk '{for( i=6; i<=NF; i++ ){printf( "%s ", $i )}; printf( "\n"); }'
    Jan 14 2014 bcomps 
    Jan 14 2014 acyclic 
    May 22 2014 skype
    

提交回复
热议问题