Finding strings through multiple lines

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding strings through multiple lines
# 1  
Old 09-21-2011
Finding strings through multiple lines

I need to search for a multiple line pattern and remove it

the pattern is search for
(ln number) <TABLE name=*>

and if 3 lines below that the line is
(ln number) </TABLE>

Then remove those 4 lines.

Thank you
# 2  
Old 09-21-2011
perl -0pe 's/\(ln number\) <TABLE name=\*>.*?\(ln number\) <\/TABLE>//s' file

# 3  
Old 09-21-2011
Sorry that didn't work I will try and be more clearer.

the (ln number) bit is the line number no brackets. There are also bits in the text which has <TABLE name=...> but when it isn't followed 3 lines later by </TABLE> I want to keep it i only want the lines deleted which follow this exact pattern

number <TABLE name=*>
number <ROW>
number </ROW>
number </TABLE>

Thank you for all the help Smilie
# 4  
Old 09-21-2011
Can you provide exact sample data?
perl -0pe 's/\d+ <TABLE name=\*>.*?\d+ <\/TABLE>//s' file

# 5  
Old 09-21-2011
want to remove
112  <TABLE name="something>
113  <ROW>
123  </ROW>
124  </TABLE>
125  <TABLE name="somethingelse>
126  <ROW>
129  </ROW>
130  </TABLE>

want to keep
493  <TABLE name="Headers_11" number="15">
494  <ROW>
495  <dest_semi_11><![CDATA[destination]]></dest_semi_11>
496  <num_semi_11><![CDATA[number sent]]></num_semi_11>
497  <cost_semi_11><![CDATA[cost]]></cost_semi_11>
498  </ROW>
499  </TABLE>

# 6  
Old 09-21-2011
perl -0pe 's/\d+\s+<TABLE name=[^>]*>\n\d+\s+<ROW>\n\d+\s+<\/ROW>\n\d+\s+<\/TABLE>\n//g' file

# 7  
Old 09-21-2011
Unfortunately that isn't working Smilie
I tried cutting out the line numbers and then doing it but it still doesn't remove anything from the script
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to find multiple strings on different lines in file?

Hello, I have spent considerable amount of time breaking my head on this and reached out here. here is the back ground. OS - Solaris 10 There are two strings '<Orin>sop' and '<Dup>two' which I wanted to look for in a file without the quotes on different lines and ONLY if both strings are... (5 Replies)
Discussion started by: keithTait309875
5 Replies

2. Shell Programming and Scripting

Exclude lines in a file with matches with multiple Strings using egrep

Hi I have a txt file and I would like to use egrep without using -v option to exclude the lines which matches with multiple Strings. Let's say I have some text in the txt file. The command should not fetch lines if they have strings something like CAT MAT DAT The command should fetch me... (4 Replies)
Discussion started by: Sathwik
4 Replies

3. Shell Programming and Scripting

Print lines between two strings multiple occurencies (with sed, awk, or grep)

Hello, I can extract lines in a file, between two strings but only one time. If there are multiple occurencies, my command show only one block. Example, monfichier.txt contains : debut_sect texte L1 texte L2 texte L3 texte L4 fin_sect donnees inutiles 1 donnees inutiles 2 ... (8 Replies)
Discussion started by: theclem35
8 Replies

4. Shell Programming and Scripting

Sed or Awk for lines between two strings multiple times and keep the last one

Hi, I am trying to get lines between the last occurrences of two patterns. I have files that have several occurrences of “Standard” and “Visual”. I will like to get the lines between “Standard” and “Visual” but I only want to retain only the last one e.g. Standard Some words Some words Some... (4 Replies)
Discussion started by: damanidada
4 Replies

5. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

6. UNIX for Dummies Questions & Answers

Finding numbers in lines with strings and number and doing some manipulation

Hi, I want to write a script that does something like this: I have a file, in which in every line, there is a string of words, and followed by some space, a number. Now, I want to identify the line, which has the largest startFace number (say m=8118), take that number and add it to the... (2 Replies)
Discussion started by: super_commando
2 Replies

7. Shell Programming and Scripting

Extract strings from multiple lines into one csv file

Hi all, Please go through my requirement. I have a log file in the location /opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch This file contains the follwing pattern data <af type="tenured" id="42" timestamp="May 14 13:44:13 2011" intervalms="955.624"> <minimum... (8 Replies)
Discussion started by: satish.vampire
8 Replies

8. Shell Programming and Scripting

replace a string with contents of a txt file containing multiple lines of strings

Hello everyone, ive been trying to replace a string "kw01" in an xml file with the contents of a txt file having multiple lines. im a unix newbie and all the sed combinations i tried resulted to being garbled. Below is the contents of the txt file: RAISEDATTIME --------------------... (13 Replies)
Discussion started by: 4dirk1
13 Replies

9. Shell Programming and Scripting

Extract strings from multiple lines into one file -

input file Desired csv output gc_type, date/time, milli secs af, Mar 17 13:09:04 2011, 144.596 af, Mar 20 00:37:37 2011, 144.242 af, ar 20 21:30:59 2011, 108.518 Hi All, Any help in acheiving the above would be appreciated. I would like to parse through lines within one file and... (5 Replies)
Discussion started by: satish.vampire
5 Replies

10. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies
Login or Register to Ask a Question