Computing.Net > Forums > Unix > Line Extraction from Script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Line Extraction from Script

Reply to Message Icon

Name: pmas
Date: July 16, 2003 at 11:35:58 Pacific
OS: Unix
CPU/Ram: P3/256
Comment:


I have data file, of following type

...
//some data..4-5 lines varies
COUNT
-DATA-// (some numbers)
//some data...again
...

this pattern repeats.

I want to extract -DATA- from this file, which always comes after line containing string COUNT, -DATA- will be numaric values.

Can you please tell me how can I do this using scripts.



Sponsored Link
Ads by Google

Response Number 1
Name: LANkrypt0
Date: July 16, 2003 at 11:56:19 Pacific
Reply:

If I am reading this correctly, you just need lines containing the word -DATA-

Why not use:
grep "-DATA-" filename


0

Response Number 2
Name: pmas
Date: July 16, 2003 at 12:25:07 Pacific
Reply:


It's not like that..

I had written -DATA- to indecate that data I am looking for comes their, that is actually a numaric value. This value comes after line containing COUNT ..
sample data file looks like as follows..
//........
No. of lines of code I have done and other documents
COUNT
100
No. of files reviewed by me
COUNT
4
Errors found while reviewing
COUNT
7
......
....
Here I want to extract
100
4
7



0

Response Number 3
Name: LANkrypt0
Date: July 16, 2003 at 13:29:04 Pacific
Reply:

grep -A1 COUNT filename | grep -v COUNT


0

Response Number 4
Name: pmas
Date: July 16, 2003 at 14:23:13 Pacific
Reply:


looks like -A1 is not one of the option of grep

Getting error..
illegal option -- -
illegal option -- A
illegal option -- 1
Usage: grep -hblcnsviw pattern file ...


0

Response Number 5
Name: James Boothe
Date: July 16, 2003 at 14:50:28 Pacific
Reply:

To print each line that follows lines that begin with COUNT:

sed -n '/^COUNT/{n;p;}' myfile


0

Related Posts

See More



Response Number 6
Name: pmas
Date: July 17, 2003 at 05:56:41 Pacific
Reply:

Thanks you very much, this is working.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Substring in Shell script FTP excel file from NT to...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Line Extraction from Script

Extracting from tar file www.computing.net/answers/unix/extracting-from-tar-file-/5377.html

Extracting lines from file using sh www.computing.net/answers/unix/extracting-lines-from-file-using-sh/7664.html

Pass options from script www.computing.net/answers/unix/pass-options-from-script/6780.html