Parse out specific lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse out specific lines
# 1  
Old 02-16-2011
Parse out specific lines

Hello,

For the life of me, I can't figure out how to extract only certain lines of a file. For example, the file contains:

Code:
project.max-sem-ids
        privileged      1.02K       -   deny                                 -
        system          16.8M     max   deny                                 -
project.max-crypto-memory
        privileged      47.1GB      -   deny                                 -
        system          16.0EB    max   deny                                 -
project.max-tasks
        system          2.15G     max   deny                                 -
project.max-lwps
        system          2.15G     max   deny                                 -
project.cpu-cap
        system          4.29G     inf   deny                                 -
project.cpu-shares
        privileged          1       -   none                                 -
        system          65.5K     max   none                                 -
zone.max-swap
        system          16.0EB    max   deny                                 -
zone.max-locked-memory
        system          16.0EB    max   deny                                 -
zone.max-shm-memory
        system          16.0EB    max   deny                                 -
zone.max-shm-ids
        system          16.8M     max   deny                                 -
zone.max-sem-ids
        system          16.8M     max   deny                                 -

and say I only want to see the values for project.max-crypto-memory and project.max-lwps for example. How would I get the 1 or 2 lines which follow which are relevant to that value?

Any help appreciated.

Thanks,

PW
# 2  
Old 02-16-2011
Code:
nawk 'NF==1{if($1!~pat) f=0;else{f=1;print};next} f' pat='project.max-crypto-memory|project.max-lwps' myFile

# 3  
Old 02-17-2011
Code:
awk '/max-crypto-memory|max-lwps/{print RS$0}' RS="project" file
project.max-crypto-memory
        privileged      47.1GB      -   deny                                 -
        system          16.0EB    max   deny                                 -
project.max-lwps
        system          2.15G     max   deny                                 -

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and replace specific positions of specific lines

Hi, I have a file with hundreds of lines. I want to search for particular lines starting with 4000, search and replace the 137-139 position characters; which will be '000', with '036'. Can all of this be done without opening a temp file and then moving that temp file to the original file name. ... (7 Replies)
Discussion started by: dsid
7 Replies

2. Shell Programming and Scripting

Parse file for fields and specific text

I have a file of ~500,000 entries in the following: file.txt chr1 11868 12227 ENSG00000223972.5 . + HAVANA exon . gene_id "ENSG00000223972.5"; transcript_id "ENST00000456328.2"; gene_type "transcribed_unprocessed_pseudogene"; gene_status "KNOWN"; gene_name "DDX11L1"; transcript_type... (17 Replies)
Discussion started by: cmccabe
17 Replies

3. Shell Programming and Scripting

Parse text file using specific tags

awk -F "" '/<href=>|<href=>|<top>|<top>/ {print $3, OFS=\t}' source.txt > output.txt I'm not quite sure how to parse the attached file, but what I am trying to do is in a output file have the link (href=), name (after the <), and count (<top>) in 3 separate columns. My attempt is the above... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

5. Shell Programming and Scripting

Parse and display specific columns

Hi.. I am in help of displaying this specific case. I have multiple files where i have to display accordingly. Input file ##INFO1 ##INFO2 ##INFO3 #CHROM POS INFO 57.sorted.bam 58.sorted.bam 59.sorted.bam 34.sorted.bam 55.sorted.bam... (12 Replies)
Discussion started by: empyrean
12 Replies

6. Shell Programming and Scripting

Print Specific lines when found specific character

Hello all, I have thousand file input like this: file1: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$ | | | |$$ $$ UERT | TTYH | TAFE | FRFG |$$ $$______|______|________|______|$$ $$ | | | |$$ $$ 1 | DISK | TR1311 | 1 |$$ $$ 1 |... (4 Replies)
Discussion started by: attila
4 Replies

7. Shell Programming and Scripting

Parse a String for a Specific Word

Hello, I'm almost there with scripting, and I've looked at a few examples that could help me out here. But I'm still at a lost where to start. I'm looking to parse each line in the log file below and save the output like below. Log File AABBCGCAT022|242|3 AABBCGCAT023|243|4... (6 Replies)
Discussion started by: ravzter
6 Replies

8. Shell Programming and Scripting

substitute a string on a specific position for specific lines

I woud like to substitue a string on a specific position for specific lines I've got a file and I would like to change a specific string from "TOCHANGE" to "ABCABCAB" For every line (except 1,2, 3 and the last one) , I need to check between the 9th and the 16th digits. For the 3rd line, I... (7 Replies)
Discussion started by: BSF
7 Replies

9. UNIX for Dummies Questions & Answers

How to parse the specific data from the file

Hi, I need to parse this data FastEthernet0/9,|FastEthernet0/10,|FastEthernet0/11,FastEthernet0/13|, FastEthernet0/12,FastEthernet0/24 . and get only the value like e.g 0/24,0/11. how to do this in shell script. Thanks in Advance. (2 Replies)
Discussion started by: MuthuAlagappan
2 Replies

10. Shell Programming and Scripting

how do i parse by specific column?

I have a log file with 13 columns. The 12th column contains the status code (example 200, 404, 500, 403, etc.) I want to remove all 200 status lines. so... 1. remove all the lines in which the 12th column has a 200. 2. display only the lines in which the 12th column shows a 500. ... (2 Replies)
Discussion started by: kmaq7621
2 Replies
Login or Register to Ask a Question