Print pattern range to a new file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print pattern range to a new file
# 1  
Old 06-27-2011
Print pattern range to a new file

Hi Everyone!

I really appreciate all of your help, I'm learning so much, can't wait until I get good enough to start answering questions!

I have a problem ... from one large file, I'd like to create multiple new files for each pattern block

beginning with /^ISA/
ending with /^IEA/

I'd even be happy with creating a new file for everything up to and including each occurence of ISA.

File is too big for csplit, I get a virtual memory exhausted error ... so I was thinking perl or awk? But I'm too new to both.

Again, I really appreciate your taking the time to help and answer questions
# 2  
Old 06-27-2011
nawk '/^ISA/ {f=1;close(file);file="file"++c}f{print > file} /^IEA/{f--}' myHugeFile

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 06-27-2011
Thank you vgersh99 ... it works perfectly! I really appreciate your time and help.

I added -mr because the lines were too long and refined the search criteria. It ended up like this:

awk -mr 99999999 '/^ISA[^[:alnum:]_]/ {f=1;close(file);file="file"++c}f{print > file} /^IEA/{f--}'

Thanks again vgersh99!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to quickly substitute pattern within certain range of a huge file?

I have big files (some are >300GB!) that need substitution for some patterns, for example, change Multiple Spaces into Tab. I used this oneliner:sed '1,18s/ \{1,\}/\t/g' infile_big.sam > outfile_big.sambut it seems very slow as the job is still running after 24 hours! In this example, only the... (8 Replies)
Discussion started by: yifangt
8 Replies

2. Shell Programming and Scripting

awk to print out lines that do not fall between range in file

In the awk below I am trying to print out those lines in file2 that are no between $2 and $3 in file1. Both files are tab-delimeted and I think it's close but currently it is printeing out the matches. The --- are not part of the files they are just to show what lines match or fall into the range... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Extract range from config file matching pattern

I have config file like this: server_name xx opt1 opt2 opt3 suboptions1 #suboptions - disabled suboptions2 pattern suboptions3 server_name yy opt1 opt2 opt3 suboptions1 pattern #suboptions - disabled suboptions2 So basically I want to extract the server... (1 Reply)
Discussion started by: nemesis911
1 Replies

4. Shell Programming and Scripting

sed command to print first instance of pattern in range

The following text is in testFile.txt: one 5 two 10 three 15 four 20 five 25 six 10 seven 35 eight 10 nine 45 ten 50 I'd like to use sed to print the first occurance of search pattern /10/ in a given range. This command is to be run against large log files, so to optimize efficiency,... (9 Replies)
Discussion started by: uschaafm
9 Replies

5. Shell Programming and Scripting

Sed print range of lines between line number and pattern

Hi, I have a file as below This is the line one This is the line two <\XMLTAG> This is the line three This is the line four <\XMLTAG> Output of the SED command need to be as below. This is the line one This is the line two <\XMLTAG> Please do the need to needful to... (4 Replies)
Discussion started by: RMN
4 Replies

6. Shell Programming and Scripting

print range of lines matching pattern and previous line

Hi all, on Solaris 10, I'd like to print a range of lines starting at pattern but also including the very first line before pattern. the following doesn't print the range starting at pattern and going down to the end of file: cat <my file> | sed -n -e '/<pattern>{x;p;}/' I need to include the... (1 Reply)
Discussion started by: siriche
1 Replies

7. Shell Programming and Scripting

Print Range Only Once Per File

Scenario: Each of several .txt files contain the following (but perhaps with some minor variations due to code version running on the devices from which the text was extracted): <output omitted> SWITCH1#show proc cpu hist 1... (4 Replies)
Discussion started by: svermill
4 Replies

8. Shell Programming and Scripting

How to print range of lines using sed when pattern has special character "["

Hi, My input has much more lines, but few of them are below pin(IDF) { direction : input; drc_pinsigtype : signal; pin(SELDIV6) { direction : input; drc_pinsigtype : ... (3 Replies)
Discussion started by: nehashine
3 Replies

9. Shell Programming and Scripting

print range between two patterns if it contains a pattern within the range

I want to print between the range two patterns if a particular pattern is present in between the two patterns. I am new to Unix. Any help would be greatly appreciated. e.g. Pattern1 Bombay Calcutta Delhi Pattern2 Pattern1 Patna Madras Gwalior Delhi Pattern2 Pattern1... (2 Replies)
Discussion started by: joyan321
2 Replies

10. UNIX for Dummies Questions & Answers

Need to print file names in a certain date range using ls

I need to list only file names of a specific date from the command ls -lt. :confused: (2 Replies)
Discussion started by: Shamwari
2 Replies
Login or Register to Ask a Question