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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help for scripting

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hiiiiiiii
i want to write a shell script which can take a unique
number as input and select some text from the abcfile
specific to that number.
The abcfle has the following syntax:
-----------------------------------------------
Unique id = x
comments: the following is the........
.......some text........
---------------------------------------------
some suff here

-------------------------------------
unique id = y
comments: the following has.......
......some text here................
-------------------------------------
some stuff here

And the whole pattern repeated in the whole file
with unique id =x and respective text may repeat anywhere in file.

i just want to get matter related to input number.
pls help me i used awk /sed but no output
Regds
Anannd
 
Anannd,

Use grep with the -n option to pick out the line number where your number/text occurs in the file.

grep -n abcfile

Then use tail to select from that line to the end of the file

Then use head to select just a few lines from that

Is that enough for you to go on or would you like an example?
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hi everybody,

You can also use the grep -p "uniqueid=1" :
it will give the whole stanza if your file is made of stanzas.

Hope this help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top