Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk and quotes 1

Status
Not open for further replies.

tempest92

Technical User
Sep 16, 2003
110
GB
hi,

can someone help please -

lsuser returns -

lsgroup -c -a id ALL
#name:id
system:0
#name:id
staff:1
#name:id
bin:2
#name:id
sys:3

i want the hostname:field1:field2 without the comments but my awk is not working !!

Code:
lsgroup -c -a id  ALL | awk -F: '$1 !~ /^#/ {print '`hostname`':$1:$2}'
 syntax error The source line is 1.
 The error context is
                $1 !~ /^#/ {print >>>  server1: <<<
 awk: The statement cannot be correctly parsed.
 The source line is 1.

thanks in advance !!
 
Hi

Code:
lsgroup -c -a id  ALL | awk -F: '$1 !~ /^#/ {print [red]"[/red]'`hostname`':[red]"[/red]$1[red]"[/red]:[red]"[/red]$2}'
Note that your code will run slowly because the [tt]hostname[/tt] executed for each line with match. Better execute it once and store its output in a variable.
Code:
lsgroup -c -a id  ALL | awk -vh="`hostname`" '!/^#/{print h":"$0}'

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top