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

Pull Data out of a file..............

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I would like to pull data out of a file:

The data will look like this:

"known name title"
blank line
"Data Line"
"Data Line"
"Data Line"
"Data Line"
.
.
"Data Line"
blank line
"known name title:"
blank line
"Data Line"
"Data Line"
"Data Line"
"Data Line"
.
.
"Data Line"

I would like to pull out the information from "known name title:" and the "Data Line"'s immediately under it down to the next blank line...

Thanks...
 
There's a realy nice example of this written in awk in the O'Reilly sed &awk book by Dale Dougherty

if your script looks like
Code:
search=$1
awk 'BEGIN { FS="\n"; RS="" }
 $0 ~ /'"$search"'/ {print  $0}' $2
Then you call it
Code:
myscript <search pattern> <file name>
 
Something like this ?
awk 'NF==0{flg=0}/known name title/{++flg}flg' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
hhhhhmmmmm if I can del the blank line after "known name title:" I would be all set.....
 
how about:

given a file:
"known name title: 1"

"Data Line1"
"Data Line1"
"Data Line1"
"Data Line1"
.
.
"Data Line"

"known name title: 2"

"Data Line2"
"Data Line2"
"Data Line2"
"Data Line2"
2.
2.
"Data Line2"

here's the awk's invokation line:
nawk -v str='known name title: 1' -f jdesp.awk jdesp.txt

Code:
BEGIN {
  RS=FS=""
}

((FNR % 2) !=0) && ($0 ~ str) {
   print;
   getline; print;
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Tried the last one:

nawk -v str='AMI pool' -f awk_codeavail_media_sorted_output
nawk: input record `BH1085 HCART NONE...' too long
input record number 1, file avail_media_sorted_output
source line number 1
 
hm........... you've got some HUGE records there, eh?

try using /usr/xpg4/bin/awk [if on Solaris]
ir if you have gawk, use gawk.

If not, you'll have to 'marshall' the lines one-by-one.

Let us know if gawk/xpg4AWK is an option.....


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
hhhmmmmm using "/usr/xpg4/bin/awk" worked... even though I didn't get the output I wanted.
 
what was wrong?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I want to just pull out a section of data... It seem to pull it all out...

If I can delete that blank line after each ""known name title".... I would be successful....
 
strange - it works just fine with my sample file and /usr/xpg4/bin/awk.

Could you post your sample file again starting from the first line, pls!

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
And this ?
awk '
NF==0{flg=0}
/known name title/{++flg;print;getline;next}
flg
' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hey Vlad.....

I posted the same in the AWK group...

I apologize for wasting your time!

(There's atleast 50 tape pools)

Pool Name 1
blank line
tape info
tape info
tape info
tape info
blank line
Pool Name 2
blank line
tape info
tape info
tape info
tape info
blank line
.
.
Pool Name X
blank line
tape info
tape info
tape info
tape info
blank line

I was thinking if I can del that blank line I can pull the data out very easy....

Plus I didn't know the AWK group existed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top