Finding a pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Finding a pattern
# 8  
Old 02-07-2011
Yin,

I should be able to delete any attribute and its content from the below example.

Input:
Code:
 
<xmlfile> ows_Body="Hi All" ows_Title="Title: Execution of Unix" ows_Author="krishna" </xmlfile>

Say If I have to delete ows_Body and its content from the input, output should be

Code:
 
<xmlfile> ows_Title="Title: Execution of Unix" ows_Author="krishna" </xmlfile>

And If I have to delete ows_Title & its content from the input, the output should be

Code:
 
<xmlfile> ows_Body="Hi All" ows_Author="krishna" </xmlfile>

Thanks,
Mahish
# 9  
Old 02-07-2011
got it,
try:
Code:
sed 's/\(.*> \)ows_Body=\(.*" \)\(ows_.*ows.*\)/\1\3/' file

# 10  
Old 02-08-2011
Appreciate your help on this.
But the solution given by you works for ows_Body= , but dont work for ows_Title.

Whatever the search element I give.. ows_Body or ows_Title, it should delete it and the data after "=" for it

Code:
 
 <xmlfile> ows_Body="Hi All" ows_Title="Title: Execution of Unix" ows_Author="krishna" </xmlfile>

If I have delete ows_Title, output should be
Code:
 
 
<xmlfile> ows_Body="Hi All" ows_Author="krishna" </xmlfile>

---------- Post updated at 10:49 AM ---------- Previous update was at 10:44 AM ----------

Also here ows_Title may not be always followed by ows_Author in the input..
We should be able to delete any data from ows_Title to next occurance of ows_
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[sed] Finding and sticking the pattern to the beginning of successive lines up to the next pattern

I have a file like below. 2018.07.01, Sunday 09:27 some text 123456789 0 21 0.06 0.07 0.00 2018.07.02, Monday 09:31 some text 123456789 1 41 0.26 0.32 0.00 09:39 some text 456789012 1 0.07 0.09 0.09 09:45 some text 932469494 1 55 0.29 0.36 0.00 16:49 some text 123456789 0 48 0.12 0.15 0.00... (9 Replies)
Discussion started by: father_7
9 Replies

2. Shell Programming and Scripting

Finding the file name in a directory with a pattern

I need to find the latest file -filename_YYYYMMDD in the directory DIR. the below is not working as the position is shifting each time because of the spaces between(occuring mostly at file size field as it differs every time.) please suggest if there is other way. report =‘ls -ltr... (2 Replies)
Discussion started by: archana25
2 Replies

3. Shell Programming and Scripting

Finding the pattern and replacing the pattern inside the file

i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of value abc and ccc in the place of them. Input File: go to &abc=ddd; if... (16 Replies)
Discussion started by: saaisiva
16 Replies

4. UNIX for Dummies Questions & Answers

Join lines on finding a pattern

I have a file with the following contents. DTP START START START DTP START DTP START DTP START I like to join the lines like this DTP START START START DTP START DTP START (2 Replies)
Discussion started by: nsuresh316
2 Replies

5. UNIX for Advanced & Expert Users

Finding a Particular Pattern In UNIX

Hi, Suppose I have a file with many lines as follows. Now I want to find the following questions from the file through shell script or commands. My name is XYZ. XYZ works for GHT and XYZ is part of PES. GHT is a good organization. XYZ knows swimming. XYZ is also very keen in reading. XYZ is a... (2 Replies)
Discussion started by: sktkpl
2 Replies

6. UNIX for Dummies Questions & Answers

Finding Pattern

Hi, i need some help regarding finding a pattern in files inside a direstory. i have these files abc123.txt cemj111.txt ckmem.txt cmick.txt crnnc.txt montt.txt xyz123.txt dfd123.txt cvv123.txt i need to find the files with name "*123.txt" which does not contain a perticular... (2 Replies)
Discussion started by: debu182
2 Replies

7. Shell Programming and Scripting

how to finding the exact pattern

I have a output like below: A1 B2 C1 D3 A12 B4 A14 I am trying to find A1 by using grep grep -i "A1" But I got (4 Replies)
Discussion started by: anupdas
4 Replies

8. UNIX for Dummies Questions & Answers

Finding a pattern with grep

I am interested in finding a pattern that looks like this AABBACC These letters are just for example but they can be any letter in the alphabet as long as they are different from each other, but the letter found in a certain spot should act like in the pattern above. Thanks! (7 Replies)
Discussion started by: moyzZ
7 Replies

9. Shell Programming and Scripting

Finding Last occurance of another pattern when a pattern is found.

Hi, I have two files viz, rak1: $ cat rak1 rak2: $ cat rak2 sdiff rak1 rak2 returns: I want the lines that got modified, changed, or deleted preceding with the section they are in. I have done this so far: (1 Reply)
Discussion started by: rakeshou
1 Replies

10. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question