I guess you should use solution in post #6 OR in post #2.
If you are new to awk/sed, you may not understand it. U need to go through some basic tutorial 1st.
post #6:
Few meanings (Look into sed manual OR some sed tutorial for more details):
-n switch to supress default output. don't print unless explicitly requested
H = > Append the content of pattern space to the hold buffer
h = > Replace contents of hold space with the contents of the pattern space
g = > Replace contents of pattern space with the contents of the hold space
p = > Copy the pattern space to the standard output
Above command does following:
1. Append every line to hold space
2. If IM pattern found, write current line to hold space (overwrite, remove old data)
3. If B2 pattern found, move hold space content to pattern space and print it to standard output.
So here if input file doesn't have IM (starting) pattern, but only B2 (Ending)Pattern, everything upto ending pattern will be printed (which is not expected I believe). So this will work good if we are sure that if there is an Ending pattern in file, there is atleast one starting pattern before that.
===============================================
Post #2:
== >> If a line has IM, store line in f
== >> If line doesn't has IM or B2, just append it to f (If f is already have some non-empty data, means IM has been found already in previous lines)
== >> If B2 is found, append it to f and print f. Set f to empty.
Last edited by anurag.singh; 01-11-2011 at 05:11 AM..
Hello,
I have attached 2 files
1) Original_table_definition.txt => which has definition of 3 tables
2) describe_table_output.txt => which has again 3 tables definition gotten thorugh doing a show table or describe table way.
Now difference between 3 tables are that tablea has no... (2 Replies)
Hi,
I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command.
Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns.
Xargs -I {} grep... (3 Replies)
Hi,
I need help to find patterns that are common or matched in a specified column in multiple files.
File1.txt
ID1 555
ID23 8857
ID4 4454
ID05 555
File2.txt
ID74 4454
ID96 555
ID322 4454 (4 Replies)
Hi,
I have code like:
Output it is comming as:
Rels: WM2
Rels: WG2
Rels: 5
- pre/prods.pl
Rels: 6
Rels: 7
Rels: 8
Rels: 10
Rels: Int
But i want only "Rels: 5" pattern Just above "- pre/prods.pl".
By... (7 Replies)
Hi,
I'm struggling to find an option for gzgrep to grep compressed files for multiple patterns preferanly using a pattern file (so pattern file can be altered seperately to rest of script).
My regex patterns are say:
4\{15\}
3\{13\}
/usr/xpg4/bin/grep will accept -f option but... (4 Replies)
I have a situation where I need to search for multiple strings (error messages) such as 'aborted' 'file not found' etc in directory having logs. I have put all the error messages in a text file and using the command.
grep -f <textfile> <filetobegrepped>
I'm doing this thru a script where I... (5 Replies)
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)
how can I search for two or more patterns in one line using grep?
for example if I want to show only the lines that have patterns "abc" and "123"?
and what if I want to show only the lines that have either "abc" or "123" in them?
any hint apprecited (4 Replies)
Hi,
I need to cut values after searching for similar patterns in a file. For example, I have the following pattern in a file:
####<Nov12 2007> <user: Vijay> <user id:123456 college:anna univ> <error code: runtime exception>
I need the values for
date:
User:
User id:
College:... (5 Replies)