Hello,
an awk style question (or a stupid question... it depends on your point of view )
How can I write in one awk command these two ones ?
$USER - `grep $USER /etc/passwd | awk -F: '{ print $5 }' | awk -F, '{ print $1 }'`
Thanks
gb
Hello,
an awk style question (or a stupid question... it depends on your point of view )
How can I write in one awk command these two ones ?
$USER - `grep $USER /etc/passwd | awk -F: '{ print $5 }' | awk -F, '{ print $1 }'`
Thanks
gb
In the awk -F option you can use a regular expression.
Check below:
# echo "a:b,c" | awk -F"[,|:]" '{print $1 " " $2 " " $3}'
a b c
Gracias Felipe for you answer,
but I'm not looking at this.
I want a sequentially awk search :
first with delimiter ":"
after with delimiter ","
br
Not sure of what you want try :
$USER - $(grep $USER /etc/passwd | awk -F: '{gsub(",","",$5); print $5}')
or
$USER - $(grep $USER /etc/passwd | awk -F: '{split($5,a,","); print a[1]}')
awk -F: '$0 ~ user {
print substr($5, 1, index($5, ",") - 1)
}' user="$USER" /etc/passwd