regex - start with a word but ignore that word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting regex - start with a word but ignore that word
# 1  
Old 06-13-2011
regex - start with a word but ignore that word

Hi Guys.

I guess I have a very basic query but stuck with it Smilie

I have a file in which I want to extract particular content. The content is between standard format like :
Verify stats
A=0
B=12
C=34
TEST Failed

Now I want to extract data between "Verify stats" & "TEST Failed" but do not want these two words in the output.
Can someone help with the regex expression to do that ?

Thanks
Ratnesh
# 2  
Old 06-13-2011
Try if this is working for you.
Code:
awk '!/(Verify stats|TEST Failed)/ { print $0 } '

# 3  
Old 06-13-2011
Or:
Code:
 awk '/TEST Failed/{flag=0}flag;/Verify stats/{flag=1}' inputFile

# 4  
Old 06-13-2011
Through sed..
Code:
sed -n '/Verify/,/TEST/{/Verify/d;/TEST/d;p}' inputfile > outfile

# 5  
Old 06-13-2011
Code:
# sed -n '/^Verify/,/^TEST/{;/TEST\|Verify/!p;}' file1

Code:
# awk '/^Verify/{next;getline txt};  $txt !~ /^TEST/ ' file1

# 6  
Old 06-13-2011
Quote:
Originally Posted by ygemici
Code:
# awk '/^Verify/{next;getline txt};  $txt !~ /^TEST/ ' file1

This is not working if we have a further line exist in the file. i.e.after "TEST Failed" .
# 7  
Old 06-13-2011
Quote:
Originally Posted by posix
This is not working if we have a further line exist in the file. i.e.after "TEST Failed" .
Code:
# awk '/^Verify/{next;getline txt};  $txt !~ /^TEST/ ; $txt ~ /^TEST/{exit}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regex to identify word in second position on a line

I am interested in finding a regex to find a word in second position on a line. The word in question is या I tried the following PERL EXPRESSION but it did not work: ] या or ^\W या But both gave Null results I am giving below a Sample file: देना या सौंपना=delegate तह जमना या... (8 Replies)
Discussion started by: gimley
8 Replies

2. Shell Programming and Scripting

What is the most widely used word anchor used in Regex?

Hello, All I learned from book about word anchor "\<" and "\>"; however when I tested them, they seem to work only in grep. Can anyone suggest word anchor that can be used in grep, awk, perl ...? (3 Replies)
Discussion started by: littlewenwen
3 Replies

3. Shell Programming and Scripting

Regex: Get the word before match

Hi Input: MYTEXT.aa.bb cc.MYTEXT.aa.bb ee.dd.cc.MYTEXT.aa.bb cc.NOTEXT.a.b Output: <empty> cc cc <empty> I would like to use a regex to extract the last word before MYTEXT without the dot (2 Replies)
Discussion started by: chitech
2 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. Shell Programming and Scripting

Regex for word followed by another word

I want to find a regex command that I can run on the command line that will find a whole word followed by another whole word (that I specify in the command). What I am looking to do is also include a file extension (like .txt) in the command such that it only runs the regex on files with that... (6 Replies)
Discussion started by: jvsrvcs
6 Replies

6. Shell Programming and Scripting

awk to ignore the text before a particular word

Hi I am new to Awk programming , i would appreciate if anyone help me with the below scenario i have text file arranged in rows and columns like below 11004 04493384 26798 CASSI0000I Server manager initialization started 111004 04493486 26798 CASSI4005I Retrieving ES... (7 Replies)
Discussion started by: rakeshkumar
7 Replies

7. Shell Programming and Scripting

start to print when a specified word is matched

Hello everybody, How can I start to print an output when a word hits the pattern space. for example: file.txt : first line second line third line fourth line ... cat file.txt > function "second" should print second line third line fourth line ... thanks for the replies now... (3 Replies)
Discussion started by: Oddant
3 Replies

8. Shell Programming and Scripting

Ignore first word using sed in PERL

Please help me in ignoring first word in a line example Input log 123^Babd^Basdf789^B098^Bouiou Desired output abd,asdf789,098,ouiou 123 should be ignored is this possible using sed regular expressions Use code tags - you got a PM with a guide. (2 Replies)
Discussion started by: thankful123
2 Replies

9. UNIX for Advanced & Expert Users

Script to ignore word from a line ...

Hi Gurus, I'm need of a script in which we are finding an independent word ‘boy' in a log file. We are using grep in order to do the same. Now in this log file there are some sentences where we see ‘This is a boy' and we do not want to count word ‘boy' from this sentence. So in other word we want... (2 Replies)
Discussion started by: heyitsmeok
2 Replies

10. Shell Programming and Scripting

Copying lines from fileA if they start by a word from fileB

Hi I'm in the need of a script that basically takes two files and generates a 3rd. It reads from fileA and fileB and copies lines from fileA if they start by a word of fileB. for example fileA The dog is beautful Where is your cat Why are you sad? Help me! fileB The Where tree dog... (4 Replies)
Discussion started by: FrancoisCN
4 Replies
Login or Register to Ask a Question