I am not sure how it works but looks like this could help me. Thank you for such a short turnaround. I will check the awk script and see how it works.
Just as a doubt can't I use a while read do loop and do the same thing. Something like this...
cat tem.exp | while read exception
do
cat file | grep -iv $exception
done
I know the above code is not right. But thats just a basic idea. I dont know how to remove a para in the first place. And then I need to do it in a loop so that I parse each line in the exception file.
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
This is a long solution, but modular for generality. It consists primarily of 2 perl scripts. The first reads paragraphs and creates single lines of them, using a character for the newline (I used "%"). The second perl script does the opposite, takes the long "%"-embedded lines, and creates separate lines.
With those two on the outside, we can manipulate the file as we wish with line-oriented *nix tools. In this demonstration a grep is used to eliminate paragraphs (long lines) matching the phrases you wish.
Here are the perl scripts:
and:
These can be driven by a shell script:
Producing:
The patterns to be excluded could contain a "%" to force exclusion of patterns ending at the point corresponding to a newline, as with pattern 3. If the character "%" occurs in either data file, then changes would need to be made to the perl scripts and the pattern data file. However, the manipulation is generally unaware that it is operating on paragraphs -- it sees everything as just a line, a long line to be sure, but just a line. This places the complexity outside the scope of the real operation you wish to perform.
The intermediate files t1 and t2 may be viewed to see in more detail how the process works. The tee commands may be removed when desired -- just delete the lines, that's why they are on separate lines in the pipeline.
The paragraphs must be separated by empty lines, no spaces, TABs, etc. are allowed, only a newline.
The first awk script runs well on one server on the other it says syntax error on line 12 where the regx occurs.
The second NAWK script that was given has a diff problem. It runs fine but it gives out all lines which dont match the pattern. I wanted to ignore the entire paragraph with matching pattern.
I cant use perl script since its not available on every server.
i have a file where the hostnames and variables are in same line in below format, am able extract some part variables while otherlike subscriptions and handler is missing.
can you please correct me if grep is able to perform this ?
cat /tmp/test
localhost subscriptions='' handler="genie"... (14 Replies)
Delete patterns matching
OS version: RHEL 7.3
Shell : Bash
I have a file like below (pattern.txt). I need to delete all lines starting with the following words (words separated by comma below) and ) character.
LOGGING, NOCOMPRESS, TABLESPACE , PCTFREE, INITRANS, MAXTRANS, STORAGE,... (3 Replies)
Hi,
I have requirement to find the matching patterns of two files in Unix. One file is the log file and the other is the error list file. If any pattern in the log file matches the list of errors in the error list file, then I would need to find the counts of the match.
For example,
... (5 Replies)
Hi Experts
I need to match 2 patterns consecutively and display 25 lines after that.
1st one - Error
2nd one - End string ( comes along with the pattern one)
3rd one - error
Logic
grep "ERROR OCCURRED :" trace.log | awk -v "ES=:" -v "SS=java.lang.NullPointerException" '{
if($NF ~... (8 Replies)
Hello all
I have a file my DNS server where there are duplicate paragrapsh like below. How can I remove the duplicate paragraph so that only one paragraph remains.
BEGIN;
replace into domains (name,type) values ('225.168.192.in-addr.arpa','MASTER');
replace into records (domain_id,... (2 Replies)
Hi Guys,
I have file like below, I want to print all lines between test1231233 to its 10 occurrence(till line 41)
test1231233
qwe
qwe
qweq123
test1231233
qwe
qwe
qweq23
test1231233
qwe
qwe
qweq123
test1231233
qwe
qwe
qweq123131 (3 Replies)
I have a file name in $f. If $f has "-" at the beginning, or "=", or does not have extension ".ry" or ".xt" or ".dat" then cerr would not be empty.
Tried the following but having some problems.
set cerr = `echo $f | awk '/^-|=|!.ry|!.xt|!.dat/'` (4 Replies)
In a directory, there are two different file extensions (*.txt and *.xyz) having similar names of numerical strings (*). The (*.txt) contains 5000 multiple files and the (*.xyz) also contains 5000 multiple files. Each of the files has around 4000 rows and 8 columns, with several unique string... (5 Replies)
IN a file I need to check for 3 patterns if all the 3 patterns are in the file. I need to send out an email. All this needs to be done in korn shell script. Please advise. (1 Reply)