Removing multiple lines from input file, if multiple lines match a pattern.
GM,
I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed.
I am assuming that sed, awk or even perl could do what I need.
I have an application that adds extra blank page feeds, for multiple reports, when sending these print jobs to CUPS.
Unfortunately, it would be very time consuming to have each of the developers go back and remove these extra page feeds, through hundreds of different reports, not to mention that would require QA, Release Management, and official patches for all of our customers.
Here's what I've done already.
I am intercepting the raw print jobs when they come into CUPS, as plain text PostScript files.
I have identified the actual lines that need to be removed from each job.
If I edit the file manually, and remove the lines manually, the subsequent printout works perfectly, with the blank pages suppressed.
But, I've been trying to use normal KSH or BASH to programatically remove the offending lines.
Unfortunately, in doing so, the script removes ALL of the necessary hidden formatting / special characters.
If I edit the file by hand, and just remove these offending lines, the document prints perfectly.
If I run the PostScript file through my "filter" script, it removes all of the special characters, and the postscript data itself is sent to the printer.
Let's say hypothetically that the following 4 lines are found. These same 4 lines can occur at different places inside of the postscript job, but normally, they will have data inserted between rows.
If these same 4 lines occur, sequentially, right after each other, without any other data, then I want to remove them:
abc
def
ghi
jkl
It is important that I must not remove any special formatting or characters from any previous or future lines within the file.
I am not looking for 4 different strings, each on it's own line. Grep -e, or egrep, would work fine for this.
I am searching for these 4 lines, together, when they appear back to back.
In order for the condition to be true, all 4 lines must exist, exactly as seen below.
In the pattern match, I need to search for something like this:
I also tried:
I also thought about using "tr" to delete the matching strings, but I'm still having an issue matching the 4 lines, to include their special characters. i.e. Line Feeds or Carriage Returns.
Unfortunately, either I'm using the wrong carriage return characters, or something is wrong with my systax.
Basically, each time the above 4 lines occur, back to back, on separate lines, I need to remove all 4 lines.
There will be times when the 4 lines will appear, where they have some other entries in the middle, such as:
Note that if there are ANY characters or data of any kind between, or in the middle of the 4 line pattern, those are valid data lines, and must not be removed.
Only when the 4 lines appear, back to back, with NOTHING else between them, or appended to them, do they need to be removed.
I hope this helps to clarify the issue.
JCF
Moderator's Comments:
Use code tags, thanks.
Last edited by zaxxon; 09-28-2015 at 11:04 AM..
Reason: code tags
Hello Gurus,
I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file.
1|ABC DEF|100|10
2|PQ
RS
T|200|20
3| UVWXYZ|300|30
4| GHIJKL|400|40... (7 Replies)
Not sure how I can accomplish this. I would like to remove all interfaces that have the commands I would like to see: switchport port-security, spanning-tree portfast. One line is no problem.
interface FastEthernet0/8
spanning-tree portfast
interface FastEthernet0/9
spanning-tree... (4 Replies)
Hello Experts , require help . See below output:
File inputs
------------------------------------------
Server Host = mike
id rl images allocated last updated density
vimages expiration last read <------- STATUS ------->... (4 Replies)
I have a file that has some lines starts with *
I want to get these lines, then get the word between "diac" and "lex".
ex.
file:
;;WORD AlAx
*0.942490 diac:Al>ax lex:>ax_1 bw:Al/DET+>ax/NOUN+ gloss:brother pos:noun prc3:0 prc2:0 prc1:0 prc0:Al_det per:na asp:na vox:na mod:na gen:m num:s... (4 Replies)
I have sql file containing lot of queries on different database table. I have to filter specific table queries.
Let say i need all queries of test1,test2,test3 along with four lines above it and sql queries can be multi lines or in single line.
Input file contains.
set INSERT_ID=1;
set... (1 Reply)
Hello People,
Need some assistance/guidance.
OUTLINE:
Two files (File1 and File2)
File1 has some ids such as
009463_3922_1827
897654_8764_5432
File2 has things along the lines of:
Query= 009463_3922_1827 length=252
(252 letters)
More stufff here
... (5 Replies)
Hi,
I'm trying to remove multiple lines of text based off a series of different words and output it to a new file
The document contains a ton of data but i want to delete any line that has the following
mx1.rr.biz.com or ns2.ri.biz.com
i tried using grep -v filename "mx1.rr.biz.com" >... (3 Replies)
I have several huge files wich contains oracle table creation scripts as follows:
I would need to remove the pattern colored in red above. Any sed/awk/pearl code will be of much help.
Thanks (2 Replies)
Hi all,
I've been working on a script which I have hit a road block now. I have written a script using sed to extract the below data and pumped into another file:
Severity............: MAJORWARNING
Summary:
System temperature is out of normal range.
Severity............: MAJORWARNING... (13 Replies)