Grab contents between two patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grab contents between two patterns
# 1  
Old 08-06-2013
Grab contents between two patterns

Hi,

What is the best approach to grab contents between

Changes

Dependencies

from the following example snippy

Code:
Changes in packages about to be updated:

bash-3.2-32.el5_9.1.x86_64
* Thu Jun 27 22:00:00 2013 Roman Rakus <rrakus@redhat.com> - 3.2-32.1
- Fixed a bug that caused trap handlers to be executed recursively,
  corrupting internal data structures.
  Resolves: #978840


Dependencies Resolved

# 2  
Old 08-06-2013
This does not include start and stop words
Code:
awk '/Changes/{f=1;next} /Dependencies/{f=0} f' file

This includes start and stop word
Code:
awk '/Changes/,/Dependencies/' file
awk '/Changes/{f=1} /Dependencies/{f=0;print} f' file

# 3  
Old 08-06-2013
I found it. Posting here helps somebody..

Code:
cat sample | sed -n '/Changes/,/Dependencies/p'
Changes in packages about to be updated:

bash-3.2-32.el5_9.1.x86_64
* Thu Jun 27 22:00:00 2013 Roman Rakus <rrakus@redhat.com> - 3.2-32.1
- Fixed a bug that caused trap handlers to be executed recursively,
  corrupting internal data structures.
  Resolves: #978840


Dependencies Resolved

---------- Post updated at 01:46 AM ---------- Previous update was at 01:45 AM ----------

Thank you Jotne Smilie

Last edited by Scott; 08-06-2013 at 06:30 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

If contents of A are in B then move the common contents to C

Hallo Team, I have 2 .csv files file A has 47600 lines and file B has 67000 lines FILEA SD0o9rb01-1d320ddbcc8d220f572739ebed5f58d1-v300g00 SD8bt0101-a0810bfe0e3396060126ec51b30dac0a-v300g00 SD05sce01-cb056af347ed4651f29eb3c3e9addbd6-v300g00... (3 Replies)
Discussion started by: kekanap
3 Replies

3. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

4. Shell Programming and Scripting

Grab nth occurence in between two patterns using awk or sed

Hi , I have an issue where I want to parse through the output from a file and I want to grab the nth occurrence of text in between two patterns preferably using awk or sed ! TICKET NBR : 1 !GSI : 102 ! 3100.2.112.1 11/06/2013 15:56:29 ! 3100.2.22.3 98 ! 3100.2.134.2... (8 Replies)
Discussion started by: OTNA
8 Replies

5. Shell Programming and Scripting

Grab the contents with in special character

I have a file which contains below kind of lines 2013-05-21 00:00:03 INFO moved to unprocessed, as doesn't exist in masklist and modified at 2013-05-20@21:21:21.000000000. 2013-05-21 00:00:03 INFO moved to unprocessed, as doesn't exist in masklist and modified at... (1 Reply)
Discussion started by: manas_ranjan
1 Replies

6. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. Shell Programming and Scripting

Grab contents between two matched patterns

I am wanting to fetch the content of the table within a file the table begins with data label like N Batch Mn(I) RMSdev I/rms Rmerge Number Nrej Cm%poss AnoCmp MaxRes CMlplc SmRmerge SmMaxRes $$ $$ . #columns of data . . . . . $$ I tried the command awk... (18 Replies)
Discussion started by: piynik
18 Replies

8. Shell Programming and Scripting

Grab the return value of df -H-m

Hi to everyone :) Quick question how do i grab the return value on the 5 position here : sgs@sibs:~$ df -H -m Sist.fichs 1M-blocos Used Available Use% Mounted on /dev/sda1 35542 18904 14833 57% / In this case the Use% value . I need to... (9 Replies)
Discussion started by: drd0spt
9 Replies

9. Programming

Need to modify contents of file with complex patterns.

hi, my fstab file content is like this along with some other lines: /dev/vg0/var1 /var1 ext3 defaults 0 2 /dev/vg0/flx1 /flx1 ext3 defaults 0 2 /dev/vg0/var /var ext3 defaults 0 1 /dev/vg0/flx /flx ext3 defaults 0 2 I want to remove lines with /dev/vg0/var and... (5 Replies)
Discussion started by: success
5 Replies

10. Shell Programming and Scripting

Searching patterns in 1 file and deleting all lines with those patterns in 2nd file

Hi Gurus, I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
Discussion started by: toms
4 Replies
Login or Register to Ask a Question