GNU bug report logs - #7076
Command required

Previous Next

Package: coreutils;

Reported by: Imran Shoaib <imran.shoaib <at> ubl.com.pk>

Date: Mon, 20 Sep 2010 15:48:02 UTC

Severity: normal

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 7076 in the body.
You can then email your comments to 7076 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 owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7076; Package coreutils. (Mon, 20 Sep 2010 15:48:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Imran Shoaib <imran.shoaib <at> ubl.com.pk>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 20 Sep 2010 15:48:02 GMT) Full text and rfc822 format available.

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

From: Imran Shoaib <imran.shoaib <at> ubl.com.pk>
To: <bug-coreutils <at> gnu.org>
Subject: Command required
Date: Mon, 20 Sep 2010 15:10:48 +0500
[Message part 1 (text/plain, inline)]
How can we extract few characters from second or third line of a text
file using cut command of Linux OS?

 

For example: to get 7-10 characters from 3rd line of a text file is
required, what can be the command?

 

 

Regards,

 

Imran

 








This E-mail and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to which
they are addressed. If you have received this E-mail in error
please notify the sender or mailto:e-help <at> ubl.com.pk. This E-mail
message and attachment, if any, has been scanned for all known
viruses, however we advice the recipient to check this E-mail and
any attachments for the presence of viruses, UBL accepts no
liability for any damage caused by any virus transmitted by this
E-mail. Further, e-mail transmission is not guaranteed as
error-free. UBL therefore does not accept liability for any errors
or omissions in the contents of any messages that arise out of
e-mail transmission.
[Message part 2 (text/html, inline)]

Reply sent to Bob Proulx <bob <at> proulx.com>:
You have taken responsibility. (Mon, 20 Sep 2010 21:19:02 GMT) Full text and rfc822 format available.

Notification sent to Imran Shoaib <imran.shoaib <at> ubl.com.pk>:
bug acknowledged by developer. (Mon, 20 Sep 2010 21:19:02 GMT) Full text and rfc822 format available.

Message #10 received at 7076-done <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Imran Shoaib <imran.shoaib <at> ubl.com.pk>
Cc: 7076-done <at> debbugs.gnu.org
Subject: Re: bug#7076: Command required
Date: Mon, 20 Sep 2010 15:21:18 -0600
Imran Shoaib wrote:
> How can we extract few characters from second or third line of a text
> file using cut command of Linux OS?

In the future please send discussion questions concerning the
coreutils to the coreutils mailing list instead of the bug-coreutils.
The bug-coreutils mailing list is for bug reports only and every email
message opens up a bug in the bug tracking system.  I am closing this
bug report but discussion may continue.  Thanks.

A good place for general help questions is help-gnu-utils <at> gnu.org.

> For example: to get 7-10 characters from 3rd line of a text file is
> required, what can be the command?

I would use sed for this.  Don't print by default (-n) and then print
the 3rd line.

  $ printf "1234567890\n1234567890\n1234567890\n" | sed -n 3p

If you want specific characters then you can delete the unwanted
ones.  This is a contrived example:

  $ printf "1234567890\n1234567890\n1234567890\n" | sed -n '3{s/^..\(..\).*/\1/;p;}'

Or you can chain commands together.  Print only the third line to a
command that pulls apart fields.

  $ printf "11 12 13\n21 22 23\n31 32 33\n" | awk 'NR==3{print$2}'
  32

  $ printf "11 12 13\n21 22 23\n31 32 33\n" | awk 'NR==3{print $2, $3}'
  32 33

> This E-mail and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to which
> they are addressed. If you have received this E-mail in error

In the future please do not include such useless and annoying
disclaimers in your email.  The terms are incompatible with a free
software mailing list.  If you cannot avoid this then please use one
of the many free email providers on the network.

Bob




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7076; Package coreutils. (Wed, 22 Sep 2010 06:51:02 GMT) Full text and rfc822 format available.

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

From: Imran Shoaib <imran.shoaib <at> ubl.com.pk>
To: <7076 <at> debbugs.gnu.org>,
	<help-gnu-utils <at> gnu.org>
Subject: RE: bug#7076: closed (Re: bug#7076: Command required)
Date: Wed, 22 Sep 2010 10:33:49 +0500
[Message part 1 (text/plain, inline)]
Thanks for the details, but what if information is to be read from file
and not from command line pattern?

For example from attached file we need to read characters 15 to 22 of
line 3 and use these characters only as input in any other file. Please
advise.


Imran
-----Original Message-----
From: GNU bug Tracking System [mailto:help-debbugs <at> gnu.org] 
Sent: Tuesday, September 21, 2010 2:19 AM
To: Imran Shoaib
Subject: bug#7076: closed (Re: bug#7076: Command required)

Your bug report

#7076: Command required

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 7076 <at> debbugs.gnu.org.

-- 
7076: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=7076
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems







This E-mail and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to which
they are addressed. If you have received this E-mail in error
please notify the sender or mailto:e-help <at> ubl.com.pk. This E-mail
message and attachment, if any, has been scanned for all known
viruses, however we advice the recipient to check this E-mail and
any attachments for the presence of viruses, UBL accepts no
liability for any damage caused by any virus transmitted by this
E-mail. Further, e-mail transmission is not guaranteed as
error-free. UBL therefore does not accept liability for any errors
or omissions in the contents of any messages that arise out of
e-mail transmission.
[sample.txt (text/plain, attachment)]

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7076; Package coreutils. (Wed, 22 Sep 2010 20:35:02 GMT) Full text and rfc822 format available.

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

From: Bob Proulx <bob <at> proulx.com>
To: Imran Shoaib <imran.shoaib <at> ubl.com.pk>
Cc: 7076 <at> debbugs.gnu.org, help-gnu-utils <at> gnu.org
Subject: Re: bug#7076: closed (Re: bug#7076: Command required)
Date: Wed, 22 Sep 2010 14:36:37 -0600
Imran Shoaib wrote:
> Thanks for the details, but what if information is to be read from file
> and not from command line pattern?

Then read the data from the file instead of the command line.

> For example from attached file we need to read characters 15 to 22 of
> line 3 and use these characters only as input in any other file. Please
> advise.

For that specific case using 'awk' is easiest for me.  In awk the FNR
variable is "the input record number in the current input file" or the
current line number.  Use it to only take action on the 3rd line of
the file.

  FNR == 3

Then the substr(s,i,n) function next seems easiest.  The substr() function
returns the substr from 's' starting at index position 'i' and
containing at most 'n' characters.  Since $0 is the current line
string we use that.

  substr($0,15,8);  # return characters 15 to 22 of the line.

Then print the result.  Putting that all together yieds this:

  $ printf "one\ntwo\nabcdefghijklmnopqrstuvwxyz\n" | awk 'FNR==3{print substr($0,15,8);}'
  opqrstuv

The command line example was how I developed the case.  Because then
everything is contained in the example and it can be shared.  You were
asking how to read a file.  Most utilities read files in the argument
list.  So to read a file simply place the file in the argument list.

  $ awk 'NR==3{print substr($0,15,8);}' /tmp/sample.txt
  DFLSDJF 

> This E-mail and any files transmitted with it are confidential and

Please do not include such useless and annoying disclaimers in your
email.  The terms are incompatible with a free software mailing list.
If you cannot avoid this because your company adds it for you then
please use one of the many free email providers on the network when
conversing on mailing lists.  Those accounts are free and freely
available and do not include such legal text.  I am unlikely to
respond to subsequent messages if they still include such legal text
in the future.

Bob




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

This bug report was last modified 14 years and 248 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.