简体   繁体   中英

Awk input and output file delimiter

I try to parse a column delimited password file using awk and put hostname in the beginning and add some fields. I need a comma separated output. So what I try is:

/usr/xpg4/bin/awk -F':'  MYHOST=$(hostname)  'BEGIN{OFS=",";} {print MYHOST, $1, $3, $4, $5;}'  /etc/passwd

But this command didn't produce output I wanted. This is a Solaris box, regular awk didn't work so I try with /usr/xpg4/bin/awk

这可以帮助您:

/usr/xpg4/bin/awk -F':'  -v MYHOST="$(hostname)"  'BEGIN{OFS=","} {print MYHOST, $1, $3, $4, $5;}'  /etc/passwd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM