How to find files containing two specific lines and delate those lines?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find files containing two specific lines and delate those lines?
# 1  
Old 10-12-2016
How to find files containing two specific lines and delate those lines?

Hi
I need to find files in a specified folder where are two specified lines of text and delate that lines. It looks like this"
Code:
35. ?>NL
36. <iframe>.......</iframe>NL

The problem is that "?>" is in the other lines and id should not be removed if the next line is not like "<iframe>....."

So the command has to read "?>NL<iframe>.......</iframe>NL" as one regex and remove only regexs exactly like this.

I can not find a solution for this
# 2  
Old 10-12-2016
Are the "35. " and "36. " part of the file?
Is "?>NL" the entire line?
Is "NL" two verbatim characters "N" and "L", or the <newline> (0x0A, \n) control character?
Are you aware that removing the closing ">" you may deteriorate your tag or even total file structure?
# 3  
Old 10-12-2016
35 and 36 are just the numbers of the lines in the editor to show that the lines are in the middle of the file. NL is "\n"

"Are you aware that removing the closing ">" you may deteriorate your tag or even total file structure?"
Yes, but only this particular one "?>" where the next line contain "<iframe....".

There are more "?>" in those php files and they have to stay.

That is why I asked:
"So the command has to read "?>NL<iframe>.......</iframe>NL" as one regex and remove only regexs exactly like this."
# 4  
Old 10-12-2016
Try
Code:
awk '
L0      {L0 = 0
         if (/^<iframe>/) next
         print "?>"
         }
/\?>/   {L0 = 1
         next
        }
1
' file

# 5  
Old 10-12-2016
Hi,

can you try the below one and check if this is what you wanted ?
Code:
sed -e '/<?/N;s,<?\n<iframe>.*</iframe>$,,' file

Quote:
cat file
#input
<?
<iframe>xyz</iframe>
hi
<?
<text>abc</text>
#comment
Gives output:
Quote:
#input

hi
<?
<text>abc</text>
#comment
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. Shell Programming and Scripting

Find specific lines between two brackets after a word

I have a file whose contents are something like below: node 'sghjknch16' { include vmware include sudo include sssd include hardening include hpom include tidal include tibco-mft-ps include jboss include... (2 Replies)
Discussion started by: proactiveaditya
2 Replies

3. Shell Programming and Scripting

ksh sed - Extract specific lines with mulitple occurance of interesting lines

Data file example I look for primary and * to isolate the interesting slot number. slot=`sed '/^primary$/,/\*/!d' filename | tail -1 | sed s'/*//' | awk '{print $1" "$2}'` Now I want to get the Touch line for only the associate slot number, in this case, because the asterisk... (2 Replies)
Discussion started by: popeye
2 Replies

4. Shell Programming and Scripting

Removing specific lines from script files.

Hello, Activity to perform: 1. Find all of the "*.tmp" files in a given user directory 2. Determine which ones have "find" in them. 3. Replace the "find sequence" of commands with a "list set" of commands. Example: Original file: -------------- define lastn1 = "A" define... (7 Replies)
Discussion started by: manishdivs
7 Replies

5. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum

Hi friends, This is sed & awk type question. It is slightly different from my previous question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers (but no more than 10 numbers in series) whenever i find it and produce an output file with the... (4 Replies)
Discussion started by: kaaliakahn
4 Replies

6. UNIX for Dummies Questions & Answers

Extract lines with specific words with addition 2 lines before and after

Dear all, Greetings. I would like to ask for your help to extract lines with specific words in addition 2 lines before and after these lines by using awk or sed. For example, the input file is: 1 ak1 abc1.0 1 ak2 abc1.0 1 ak3 abc1.0 1 ak4 abc1.0 1 ak5 abc1.1 1 ak6 abc1.1 1 ak7... (7 Replies)
Discussion started by: Amanda Low
7 Replies

7. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

8. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 Replies

9. Shell Programming and Scripting

Concatenate lines between lines starting with a specific pattern

Hi, I have a file such as: --- >contig00001 length=35524 numreads=2944 gACGCCGCGCGCCGCGGCCAGGGCTGGCCCA CAGGCCGCGCGGCGTCGGCTGGCTGAG >contig00002 length=4242 numreads=43423 ATGCCGAAGGTCCGCCTGGGGCTGG CGCCGGGAGCATGTAGCG --- I would like to concatenate the lines not starting with ">"... (9 Replies)
Discussion started by: s052866
9 Replies

10. Shell Programming and Scripting

Substitute specific lines with lines from another file

Hello All, I am new to this forum. I am currently facing a problem in manipulating files. I have two files called old-matter and new-matter # cat old-matter abc: this, is a, sample, entry byi: white board, is white in color rtz: black, board is black qty: i tried, a lot asd: no... (1 Reply)
Discussion started by: rahmathulla
1 Replies
Login or Register to Ask a Question