GNU bug report logs - #22886
Request to get First column of first row

Previous Next

Package: grep;

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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 22886 in the body.
You can then email your comments to 22886 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#22886; Package grep. (Thu, 03 Mar 2016 00:41:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Kannan E1" <kannane1 <at> in.ibm.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Thu, 03 Mar 2016 00:41:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Kannan E1" <kannane1 <at> in.ibm.com>
To: bug-grep <at> gnu.org
Subject: Request to get First column of first row
Date: Thu, 3 Mar 2016 05:49:25 +0530
[Message part 1 (text/plain, inline)]
Hi Team,

We are facing issue to get output of first column of first row.

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.


Regards,

Kannan E
Technical Services Specialist - AIX
Regional Delivery Center,Chennai
GTS SO Delivery


Phone: +91-44-43425121 | Mobile: +91 9790254488
E-mail: kannane1 <at> in.ibm.com


DLF IT Park,Blk 7, 5th Floor
Chennai, TN 600089
India


[Message part 2 (text/html, inline)]
[Message part 3 (image/gif, inline)]

Information forwarded to bug-grep <at> gnu.org:
bug#22886; Package grep. (Thu, 03 Mar 2016 01:17:02 GMT) Full text and rfc822 format available.

Message #8 received at 22886 <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Kannan E1 <kannane1 <at> in.ibm.com>
Cc: 22886 <at> debbugs.gnu.org
Subject: Re: bug#22886: Request to get First column of first row
Date: Wed, 2 Mar 2016 18:16:22 -0700
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




Added tag(s) notabug. Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Thu, 03 Mar 2016 01:17:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 22886 <at> debbugs.gnu.org and "Kannan E1" <kannane1 <at> in.ibm.com> Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Thu, 03 Mar 2016 01:17:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 31 Mar 2016 11:24:04 GMT) Full text and rfc822 format available.

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.