How to fetch a string between two different strings?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to fetch a string between two different strings?
# 8  
Old 04-26-2012
How to fetch a string between two different strings

Hi Scrut,

Thanks, I understand that RS record sperator and FS is field ..
It is little confusing to me here that how exactly awk is understanding record here and then using FS to get value.

Can you please let me know from this example?

Record1=?

Record2=?

Thanks
Krsna
# 9  
Old 04-26-2012
Quote:
Originally Posted by krsnadasa
Hi Raj,

Just want to know what is the meaning of -F"[<>]". I understand that we are defining delimeter but what exactly menaing of above.

Thanks
Krsnadasa
-F"[><]" --> we are giving two field seperator >< ( if any one occurs, then field will be seperated )
This User Gave Thanks to itkamaraj For This Post:
# 10  
Old 04-26-2012
Quote:
Originally Posted by krsnadasa
Hi Scrut,

Thanks, I understand that RS record sperator and FS is field ..
It is little confusing to me here that how exactly awk is understanding record here and then using FS to get value.

Can you please let me know from this example?

Record1=?

Record2=?

Thanks
Krsna
Hi, Krsna, maybe this helps:

Code:
$ awk '{print NR,$0}' RS=\< infile
1 
2 name>usrname
3 /name> 
4 value>ravistej
5 /value>

6 name>pswd
7 /name> 
8 value>asdfgzxcv
9 /value>
.
.
.
.

10 name>abc
11 /name> 
12 value>xyz
13 /value>

Code:
$ awk '/^value/{print NR,$0}' RS=\< infile
4 value>ravistej
8 value>asdfgzxcv
12 value>xyz

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

To Fetch values from String

Dears, I have string like below in my csv file <someTechnicalDetails><someTechnicalDetails>HSI</someTechnicalDetails,1234564 <someTechnicalDetails><someTechnicalDetails>Voice</someTechnicalDeta,12345673 <someTechnicalDetails><someTechnicalDetails>IPTV</someTechnicalDetai,12345673 and I... (2 Replies)
Discussion started by: mirwasim
2 Replies

2. Shell Programming and Scripting

Fetch Valid String

Hi All, How to fetch the particular row based on my search command. For example Source Column Column A Column B 001,56123456 002,57123456 003,123456 Expected Output: 003,123456 To get this output I tried below mentioned function grep '123456' filename.txt (4 Replies)
Discussion started by: suresh_target
4 Replies

3. Shell Programming and Scripting

Cut & Fetch word from string

I have a file with some SQL query, I want to fetch only Table Name from that file line by line. INPUT FILE SELECT * FROM $SCHM.TABLENAME1; ALTER TABLE $SCHM.TABLENAME1 ADD DateOfBirth date; INSERT INTO $SCHM.TABLENAME1 (CustomerName, Country) SELECT SupplierName, Country FROM $SCHM.TABLENAME2... (2 Replies)
Discussion started by: Pratik Majithia
2 Replies

4. 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

5. Solaris

Search string between the strings

File name : Sample.txt <ownername>Oracle< ownername> I am new to unix world , i would like to search string and return back to another sh script. bascially i want to read file Sample.txt find the string between <ownername> Sample.txt < ownername> . Gerneric way to find the string... (15 Replies)
Discussion started by: balajikalai
15 Replies

6. Shell Programming and Scripting

Fetch the rows with match string on a fixed lenth text file - NO delimiters

Hi I am trying to fetch the rows with match string "0000001234" Input file looks like below: 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1... (6 Replies)
Discussion started by: nareshk
6 Replies

7. Shell Programming and Scripting

To replace string between two strings

how do i replace a string within two strings ?. i have a string called my_string i.e my_string="GACAHX04GAC010000000001DDELTA 0001DAT00001320SLTZ" i need to replace all characters between DAT and SLTZ with zeros, the number of characters between these strings might vary . i.e output ... (1 Reply)
Discussion started by: amit1_x
1 Replies

8. Shell Programming and Scripting

How to fetch variable value in if block and to compare it with certain string

Hi, I am trying to execute this command if ; then but getting error .Some problem with reteriving the value of $exception_info. Please help.Its urgent. thanks (4 Replies)
Discussion started by: khushboo
4 Replies

9. Shell Programming and Scripting

fetch string and insert later

"are you billy_smith ?" replace with "are you billy_smith ? my name is billy_smith" how to fetch the name "billy_smith" and using it later I need sed script to do this, any one can help? Thanks (6 Replies)
Discussion started by: playinmel.com
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