awk doesn't print separator

前端 未结 2 1135
遇见更好的自我
遇见更好的自我 2021-01-26 09:42

I\'m running this awk program :

awk -F: \'{if($1==\"waheed\") {$2=1;print $0}}\' /etc/passwd

and the output is:

mysql 1 118 129         


        
相关标签:
2条回答
  • 2021-01-26 10:23

    In awk output is seperated by the contents of the OFS ( output field seperater ) variable a space by default. This can be set with -v OFS=':'

    awk -F : -v OFS=':' '{ cmds}' file
    
    0 讨论(0)
  • 2021-01-26 10:25

    you can directly use awk command like this :

    awk 'BEGIN{OFS=":"} {your code here}'
    

    all codes in begin quotes runs only onetime

    and the -v option is for to trans your parameter into your scripts. like:

    awk '{print $pid_doc}' -v pid_doc="$Param"
    

    and this $Param can be given from your shell script

    0 讨论(0)
提交回复
热议问题