How to specify more spaces for the delimiter using cut?

前端 未结 12 695
遥遥无期
遥遥无期 2020-12-04 05:51

Is there any way to specify a field delimiter for more spaces with the cut command? (like \" \"+) ? For example: In the following string, I like to reach value \'3744\', wha

12条回答
  •  忘掉有多难
    2020-12-04 06:10

    If you want to pick columns from a ps output, any reason to not use -o?

    e.g.

    ps ax -o pid,vsz
    ps ax -o pid,cmd
    

    Minimum column width allocated, no padding, only single space field separator.

    ps ax --no-headers -o pid:1,vsz:1,cmd
    
    3443 24600 -bash
    8419 0 [xfsalloc]
    8420 0 [xfs_mru_cache]
    8602 489316 /usr/sbin/apache2 -k start
    12821 497240 /usr/sbin/apache2 -k start
    12824 497132 /usr/sbin/apache2 -k start
    

    Pid and vsz given 10 char width, 1 space field separator.

    ps ax --no-headers -o pid:10,vsz:10,cmd
    
      3443      24600 -bash
      8419          0 [xfsalloc]
      8420          0 [xfs_mru_cache]
      8602     489316 /usr/sbin/apache2 -k start
     12821     497240 /usr/sbin/apache2 -k start
     12824     497132 /usr/sbin/apache2 -k start
    

    Used in a script:-

    oldpid=12824
    echo "PID: ${oldpid}"
    echo "Command: $(ps -ho cmd ${oldpid})"
    

提交回复
热议问题