reading specifiec records from a file!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading specifiec records from a file!!
# 1  
Old 03-20-2007
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
# 2  
Old 03-20-2007
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
# 3  
Old 03-20-2007
Code:
grep [^a-zA-Z] filename

# 4  
Old 03-20-2007
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??
# 5  
Old 03-20-2007
Code:
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
Code:
grep [0-9] ss

10 11 12

o/p
13 14 15
16 17 18
19 20 21
# 6  
Old 03-20-2007
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.

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

# 7  
Old 03-20-2007
reborg,

it works :-) 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

1. This will insert the records into db table by reading from ta csv file

I have this code with me but the condition is If any of the mandatory columns are null then entire file will be rejected. LOAD DATA infile ' ' #specifies the name of a datafile containing data that you want to load BADFILE ' ' #specifies the name of... (1 Reply)
Discussion started by: raka123
1 Replies

2. Shell Programming and Scripting

Shell script to filter records in a zip file that contains matching columns from another file

Not sure if this is the correct forum for this question. I have two files. file1.zip, file2 Input: file1.zip col1, col2 , col3 a , b , 0:0:0:0:0:c436:9346:d40b x, y, 0:0:0:0:0:880:39f9:c9a7 m, n , 0:0:0:0:0:80c7:9161:fe00 file2.txt col1 c4:36:93:46:d4:0b... (1 Reply)
Discussion started by: anil.v
1 Replies

3. Shell Programming and Scripting

Separate records of a file on 2 types of records

Hi I am new to shell programming in unix Please if I can provide help. I have a file structure of a header record and "N" detail records. The header record will be the total number of detail records I need to split the file in 2: One for the header Another for all detail records Could... (1 Reply)
Discussion started by: jamcogar
1 Replies

4. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

5. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

6. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

7. Shell Programming and Scripting

Based on num of records in file1 need to check records in file2 to set some condns

Hi All, I have two files say file1 and file2. I want to check the number of records in file1 and if its atleast 2 (i.e., 2 or greater than 2 ) then I have to check records in file2 .If records in file2 is atleast 1 (i.e. if its not empty ) i have to set some conditions . Could you pls... (3 Replies)
Discussion started by: mavesum
3 Replies

8. UNIX for Dummies Questions & Answers

Use records from one file to delete records in another file

file_in_1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 file_in_2: 9 10 11 12 21 22 23 24 1 2 3 4 17 18 19 20 file_out: (5 Replies)
Discussion started by: kenneth.mcbride
5 Replies

9. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies

10. UNIX for Dummies Questions & Answers

Issue with reading in records

Hi all, This is my first post here, so please bear with me! I have a file coming into a korn shell script, fixed length. Example: Peter (25 spaces) D (29 spaces) Younan (24 spaces) Jim (27 spaces) (30 spaces) ... (4 Replies)
Discussion started by: peteroc
4 Replies
Login or Register to Ask a Question