The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search a pattern in a file with contents in a single line sparks Shell Programming and Scripting 4 03-17-2009 02:51 AM
find pattern, delete line with pattern and line above and line below nickg Shell Programming and Scripting 4 01-29-2009 01:38 PM
find pattern delete line with pattern and line above and line below nickg UNIX for Dummies Questions & Answers 1 01-28-2009 06:46 PM
Split File Based on Line Number Pattern shankster Shell Programming and Scripting 11 10-01-2008 10:49 AM
how to move the line after a certain pattern in the file aoussenko Shell Programming and Scripting 5 09-03-2008 04:21 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-16-2009
DTechBuddy DTechBuddy is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 17
Question Get value in between a pattern from each line in file

Hi Guyz,

I have a flat file with some data as below:-

Quote:
<ABC>hello</ABC><XYZ>I want This</XYZ><CDF>World</CDF>
<ABC>Vzup</ABC><XYZ>This data is Needful</XYZ><CDF>Moon</CDF>
I need only the data within tags <XYZ>, from each line of the file.

My desired output:-

Quote:
I want This
This data is Needful


Tried a lot, but not getting the desired result.
Thnx in advance.
  #2 (permalink)  
Old 07-16-2009
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
This might help.
  #3 (permalink)  
Old 07-16-2009
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,411
Try...
Code:
awk -F '</?XYZ>' 'NF==3{print $2}' file1

  #4 (permalink)  
Old 07-28-2009
DTechBuddy DTechBuddy is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 17
Thankz

Thnx Ygor.
It worked.
  #5 (permalink)  
Old 07-28-2009
gch gch is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 26
There is overreliance on awk. There are cases in which files are very large (log files) and using awk can literally take minutes to process such files.
The most efficient way is to use regular expressions.
Try this:

Code:
grep 'XYZ>..*</XYZ' filename

  #6 (permalink)  
Old 07-28-2009
edidataguy edidataguy is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 173
Quote:
Originally Posted by gch View Post
There is overreliance on awk. There are cases in which files are very large (log files) and using awk can literally take minutes to process such files.
The most efficient way is to use regular expressions.
Try this:

Code:
grep 'XYZ>..*</XYZ' filename
GCH
What do you think this will do?
What is the requirement?
Did you test it?
This will just list all the lines once again.
That will be garbage-in-garbage-out.
  #7 (permalink)  
Old 07-28-2009
gch gch is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 26
Quote:
Originally Posted by edidataguy View Post
GCH
What do you think this will do?
What is the requirement?
Did you test it?
This will just list all the lines once again.
That will be garbage-in-garbage-out.
Sorry. I was doing too many things at the time. I did not paste the correct line.
This is it:

Code:
cut -d \> -f4 filename | cut -d\< -f1

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0