filtering between marker


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting filtering between marker
# 1  
Old 06-02-2010
[solved]filtering between marker

Hi everyone,

I have a very big git log, and I want to extract the part
between 2 DIFFERENT markers(the marker is something like
a serial number d1938d11e7eb4d845cfe1f3c6bc5899b5ac538a7
)

beginning of the log
<marker1>
part of the log I'm interessed in
<marker2>
rest of the log

apparently I cannot do it using grep, and I have not managed to do it
using awk. Could someone help me do it please?

Last edited by solal; 06-02-2010 at 09:46 PM.. Reason: solution given. thanks
# 2  
Old 06-02-2010
Code:
perl -ne 'print if /^<marker1>$/../^<marker2>$/;' yourfile

Note that this will print to the console, so redirect it to a file if needed. Also, both marker lines will be included.
# 3  
Old 06-02-2010
If you know the sha1's (markers), then you could try

Code:
$ sed -n '/marker1/,/marker2/p' logfile

# 4  
Old 06-02-2010
Try:
Code:
awk '/^<marker2>/{p=0}p;/^<marker1>/{p=1}' infile

output:
Code:
part of the log I'm interessed in

# 5  
Old 06-02-2010
Quote:
Originally Posted by pludi
Code:
perl -ne 'print if /^<marker1>$/../^<marker2>$/;' yourfile

Note that this will print to the console, so redirect it to a file if needed. Also, both marker lines will be included.
Could you give some link describing that perl syntax? Is ".." part of regex or if statement?
# 6  
Old 06-02-2010
I think I'm gonna cry :_), I tried to do it for one hour, one hour and a half

Thank you all. I used Scrutinizer technique as I was trying to do it
with awk. Now I can extract easily my push between release.


Should I edit the thread to add [solved] ?
# 7  
Old 06-02-2010
@solal: Yes please.

@bartus11: neither. Usually, two dots mean a range, as in 1..5. However, since TMTOWTDI, it can also act as a flip-flop (yes, just like in electronics). In this case, the first regex sets the flip-flop to always return true (thus printing a line), untill the second regex sets it back to false (thus disabling printing). See Range Operators in perlop.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on filtering

Hi experts, I have a file image.csv as below: COMPUTERNAME,23/07/2013,22/07/2013,21/07/2013,20/07/2013,19/07/2013,18/07/2013,17/07/2013 AED03852180,3,3,3,3,3,3,3 AED03852181,3,3,3,3,3,3,1 AED09020382,3,0,3,0,3,3,3 AED09020383,1,3,3,3,2,1,3 AED09020386,3,3,0,3,3,0,3 ... (4 Replies)
Discussion started by: zaq1xsw2
4 Replies

2. Shell Programming and Scripting

OSX, bash, cat with <<MARKER executing commands

I have a script that writes another script with cat >/usr/local/bin/myscript.sh <<EOF #!/bin/sh VAR=`run a command here` EOF Problem is, after this is run, I get: $ cat /usr/local/bin/myscript.sh #!/bin/sh VAR=result of command How do I stop that from happening with Macs... (2 Replies)
Discussion started by: jnojr
2 Replies

3. UNIX for Dummies Questions & Answers

Filtering the duplicates

Hello, I want to filter all the duplicates of a record to one place. Sample input and output will give you better idea. I am new to unix. Can some one help me on this? Input: 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr1.fa chr1.fa... (2 Replies)
Discussion started by: koneru_18
2 Replies

4. Shell Programming and Scripting

Filtering

Hi I am interested in DNS resolving a set of sites and each time the output is different- $ host www.yahoo.com www.yahoo.com is an alias for fd-fp3.wg1.b.yahoo.com. fd-fp3.wg1.b.yahoo.com is an alias for ds-fp3.wg1.b.yahoo.com. ds-fp3.wg1.b.yahoo.com is an alias for... (1 Reply)
Discussion started by: jamie_123
1 Replies

5. AIX

Need help with filtering

Hi!! I have a bit of a task here and filtering/scripting not my strongest. I have to collect info of approx 1100 hdiskpower.so i have appended all the hdisk into a text file and i need it to run the command lscfg -vl to confirm if the drive is symmetrix. here's what i have so far at... (3 Replies)
Discussion started by: vpundit
3 Replies

6. Shell Programming and Scripting

perl : replace multiline text between two marker points

Hi there I just wondered if someone could give me some perl advice I have a bunch of text files used for a wiki that have common headings such as ---++ Title blah ---++ Summary blah ---++ Details Here is the multiline block of text I wish to (6 Replies)
Discussion started by: rethink
6 Replies

7. Shell Programming and Scripting

Please help me to do some filtering

I have to grep a pattern. scenario is like :- Suppose "/etc/sec/one" is a string, i need to check if this string contains "one" using any utility something like if /etc/sec/one | grep ; then Thanks in advance Renjesh Raju (3 Replies)
Discussion started by: Renjesh
3 Replies

8. Shell Programming and Scripting

Print after pattern and insert marker

Struggling today with formatting some data but getting there thx to help here. 1. I want to search for a pattern and print every line after the pattern up to a second specified pattern. 2. Then I want to put a marker above the second pattern. Input File: FROM aaa bbb ccc aaa ... (3 Replies)
Discussion started by: lewk
3 Replies

9. UNIX for Dummies Questions & Answers

Filtering out data ...

I have following command which tells me File size in GBs which are greater than 0.01GBs recursively in a dir structure. ls -l -R | awk '{ if ($5/1073741824 >= 0.01) print $9, $5/1073741824 }' But there are some files whom I dont have enough permissions, after executing this script gives me... (1 Reply)
Discussion started by: videsh77
1 Replies
Login or Register to Ask a Question