GNU bug report logs -
#22886
Request to get First column of first row
Previous Next
Reported by: "Kannan E1" <kannane1 <at> in.ibm.com>
Date: Thu, 3 Mar 2016 00:41:02 UTC
Severity: normal
Tags: notabug
Done: Bob Proulx <bob <at> proulx.com>
Bug is archived. No further changes may be made.
Full log
Message #12 received at control <at> debbugs.gnu.org (full text, mbox):
tag 22886 + notabug
close 22886
thanks
Your email to the bug reporting address opens a bug ticket
automatically. Since you are not reporting a bug but are simply
asking for scripting help I will go ahead and close the ticket.
Kannan E1 wrote:
> We are facing issue to get output of first column of first row.
To get the first row you could use head.
head -n1
To get the first column you could use awk.
awk '{print$1}'
To do both you could do this:
... | head -n1 | awk '{print$1}'
> hscroot <at> vahmc032:~> viosvrcmd -m Server-XXXXXXX -p va10XXX-VIOS2 -c "lsmap -all -npiv" | grep -i va10XXX
Using your example you could do this to get the first column of the
first row.
viosvrcmd -m Server-XXXXXXX -p va10XXX-VIOS2 -c "lsmap -all -npiv" | head -n1 | awk '{print$1}'
Awk is powerful enough to do both of those and much more. NR is the
Number of Records. If the NR (Number of Records) is equal to 1 then
that is the first line. The first line being the first row testing
for NR==1 is a pattern match that matches the first line only. Then a
small optimization is to exit immediately so as not to read any of the
rest of the input.
viosvrcmd -m Server-XXXXXXX -p va10XXX-VIOS2 -c "lsmap -all -npiv" | awk 'NR==1{print$1;exit}'
> Please guide us to get only vfchostX column alone.Thanks...
>
> hscroot <at> vahmc032:~> viosvrcmd -m Server-XXXXXXX -p va10XXX-VIOS2 -c "lsmap
> -all -npiv" | grep -i va10XXX
> vfchost46 U9117.MMC.10E45C6-V2-C180 15 va10XXXXX AIX
>
> Note: awk '{print $1}' is not working.
These types of shell scripting questions are probably better sent to
the help-gnu-utils <at> gnu.org discussion mailing list. Email there won't
open a bug ticket. That is generally the best place for random
scripting questions using the utilities. Since this ticket has
already been started please continue the conversation here for this
discussion. Please keep 22886 <at> debbugs.gnu.org in the recipient list
for this topic.
Bob
This bug report was last modified 9 years and 143 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.