Search string between the strings


 
Thread Tools Search this Thread
Operating Systems Solaris Search string between the strings
# 8  
Old 10-13-2010
Or:
Code:
awk -F"<|>" '/<schema>/{print $3}'

# 9  
Old 10-13-2010
Code:
sed -n 's|.*<\(ownername\)>\(.*\)</*\1>.*|\2|p'


Last edited by Scrutinizer; 10-13-2010 at 03:47 PM..
# 10  
Old 10-13-2010
Java unix

thank you so much for your help

my input file Sample.txt format has changed little bit </owner_name>

line 1
<owner_name>balaji</owner_name>
line 2
line 3
line 4

please help me for the same.
# 11  
Old 10-13-2010
Quote:
Originally Posted by Scrutinizer
Code:
sed -n 's|.*<\(ownername\)>\(.*\)<\/*\1>.*|\2|p'

Since slash is a meta-char, you need \/ or [/].

---------- Post updated at 03:16 PM ---------- Previous update was at 03:15 PM ----------

Code:
sed '
  s/.*<schema>\([^<]*\)<\/schema>.*/\1/
  t quit
  d
  :quit 
  q
 ' Sample.txt

# 12  
Old 10-13-2010
Quote:
Originally Posted by balajikalai
my input file Sample.txt format has changed little bit
Code:
sed -n 's|.*<\(owner_name\)>\(.*\)</*\1>.*|\2|p' infile



---------- Post updated at 21:20 ---------- Previous update was at 21:17 ----------

Quote:
Originally Posted by DGPickett
Since slash is a meta-char, you need \/ or [/].
Hi DGPickett, actually I don't think I do, since I am using | as the separator, so it isn't a metacharacter in this case.
# 13  
Old 10-13-2010
True, I stand corrected -- must have had my head tilted.

You just do not exit after the first hit is printed.

I have not used many options like post-s p only good with -n because they are utterly redundant to other, more modular, less limited, more general pieces, and space in my head is more precious than disk space. Commands are designed by committee, it seems.
# 14  
Old 10-13-2010
Quote:
Originally Posted by DGPickett
You just do not exit after the first hit is printed..
Your right, it is not that efficient, but the idea is that there may be more then one pair of tags (each on the same line otherwise it will not work), to quit I'll gladly use your solution Smilie

Code:
sed 's|.*<\(owner_name\)>\(.*\)</*\1>.*|\2|;te;d;:e;q' infile



---------- Post updated at 22:02 ---------- Previous update was at 21:36 ----------

This should work with content spread over more than one line
Code:
awk '$2=="/owner_name"{gsub(/\n/," ",$1);print $1}' FS=\< RS=\> infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search strings from a file in files in a directory recursively; then print the string with a status

Hi All, I hope somebody would be able to help me. I would need to search a string coming from a file, example file.txt: dog cat goat horse fish For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Discussion started by: kokoro
9 Replies

2. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

3. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

4. Shell Programming and Scripting

Multiple search strings replaced with single string

Hi, I need someone's help in writing correct perl code. I implemented following code for "multiple search strings replaced with single string". ========================================================= #!/usr/bin/perl my $searchStr = 'register_inst\.write_t\(' |... (2 Replies)
Discussion started by: chettyravi
2 Replies

5. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

6. Shell Programming and Scripting

Search for string in a file, extract two another strings and concatenate to a variable

I have a file with <suit:run date="Trump Tue 06/19/2012 11:41 AM EDT" machine="garg-ln" build="19921" level="beta" release="6.1.5" os="Linux"> Need to find word "build" then extract build number, which is 19921 also release number, which is 6.1.5 then concatenate them to one variable as... (6 Replies)
Discussion started by: garg
6 Replies

7. Shell Programming and Scripting

awk search an output string between two strings

I would like to search for strings stored in searchstringfile.txt in inputfiles. searchstringfile.txt J./F. Gls. Wal F. Towerinput1.txt What is needed is J./F. 12 var Gls. Wal 16 interp. Tower 12 input2.txt Awk shall search for F. 16 pt. J./F. 22 output.txt input1.txt J./F. = 12 var... (3 Replies)
Discussion started by: sdf
3 Replies

8. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

9. Shell Programming and Scripting

Search multiple strings on a file and copy the string next to it

I tried awk for this, but failed <or my code is not correct? I dont know>. Can anyone help me on this? ---------- Post updated at 08:34 PM ---------- Previous update was at 08:29 PM ---------- my working file looks like this: <empty> <empty> <empty> NAME :ABC AGE :15 GENDER... (6 Replies)
Discussion started by: kingpeejay
6 Replies

10. Shell Programming and Scripting

How to concatenate two strings or several strings into one string in B-shell?

like connect "summer" and "winter" to "summerwinter"? Can anybody help me? thanks a lot. (2 Replies)
Discussion started by: fontana
2 Replies
Login or Register to Ask a Question