Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
bug#7076: closed (Re: bug#7076: Command required)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Imran Shoaib  
View profile  
 More options Sep 22 2010, 1:33 am
Newsgroups: gnu.utils.help
From: Imran Shoaib <imran.sho...@ubl.com.pk>
Date: Wed, 22 Sep 2010 10:33:49 +0500
Local: Wed, Sep 22 2010 1:33 am
Subject: RE: bug#7076: closed (Re: bug#7076: Command required)

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

  sample.txt
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Proulx  
View profile  
 More options Sep 22 2010, 4:36 pm
Newsgroups: gnu.utils.help
From: Bob Proulx <b...@proulx.com>
Date: Wed, 22 Sep 2010 14:36:37 -0600
Local: Wed, Sep 22 2010 4:36 pm
Subject: Re: bug#7076: closed (Re: bug#7076: Command required)

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »