reading specifiec records from a file!!

I want to read all numeric records that start with the line id and write them to a new file.

input:

blah blah
blah blah
id
10 11 12
13 14 15

blah blah
blah blah
id
16 17 18
19 20 21

output:
10 11 12
13 14 15
16 17 18
19 20 21

any idea please??

thanks

andy

sed '/^[0-9]/!d' filename
or
awk '/^[0-9]/' filename
or
grep '^[0-9]' filename

Output:
u142115@linux2alm:~/aps/aps4/product/den> sed '/^[0-9]/!d' new
10 11 12
13 14 15
16 17 18
19 20 21
u142115@linux2alm:~/aps/aps4/product/den> awk '/^[0-9]/' new
10 11 12
13 14 15
16 17 18
19 20 21
u142115@linux2alm:~/aps/aps4/product/den> grep '^[0-9]' new
10 11 12
13 14 15
16 17 18
19 20 21

grep [^a-zA-Z] filename

sorry... but that is very easy :-))

since sometimes I have the situation;
blah blah
55 67 88
blah blah
id
10 11 12
13 14 15

blah blah
id
10 11 12
13 14 15

so the script should go to "id" reads the following numeric lines until new line and so on. How to solve the problem??

grep [^0-9] ss

( where ss is filename)
blah blah
blah blah
id
10 11 12
13 14 15
blah blah
blah blah
id
16 17 18
19 20 21
which is not giving proper o/p as you want

try this

grep [0-9] ss

10 11 12

o/p
13 14 15
16 17 18
19 20 21

That is exactly what the OP is not looking for, that would match any line with any numbers.

Andy, I think this does what you were asking for,
if I understood correctly.

awk '/^id/{getline; while ( NF ) { print; getline} }' file

reborg,

it works :slight_smile: but with a small bug "endlessly loop".. it happens if the last line a none new line.

how can tell awk to skip reading if end of file??

Thanks

andy

awk '/^id/{getline; x=NR; while ( NF && NR == x ) { print ; getline; x++; } }' filename

I want to exit the loop if $0 includes a character like ^F (dec 06).

How can I do it in awk???

Thanks

check it with the match operator in awk

if ( match($0, character) ) { exit }

matrixmadhan,

is there a better way like the following to handle with character:

character= sprintf("%c",6);
if ( match($0, character) ) { exit }