Show how you can use awk on the command line to print the first field of the /etc/passwd file if the file uses a colon ":" as the delimeter.
Any help woudl be appreciated
Three answers:
mgerben
2008-03-03 09:13:42 UTC
something like this...
awk 'BEGIN {FS=":"} print $1; exit; ' /etc/passwd
Sets the field separator to colon before beginning; prints the 1st field of the 1st line and then exits.
You may have to work out the single and double quotes on this one.
I almost always run awk scripts from files - saves me trouble with quoting and escaping from the commandline. If my prog does not work at least I know it's not the quotes.
pv2omni
2008-03-03 09:13:09 UTC
It is a Unix command that won't work in Windows. If you're in Unix you can get help by typing "man awk".
I hope that helps.
CC
2008-03-03 09:09:13 UTC
A one liner?
Errr...
A bike can't stand on it's own as it's too tyred.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.