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
extracting data from files.. anchal_khare Shell Programming and Scripting 1 04-03-2008 07:56 AM
extracting integer from data grotesque Shell Programming and Scripting 4 01-18-2008 08:18 AM
Extracting a string from one file and searching the same string in other files mohancrr Shell Programming and Scripting 1 09-19-2007 04:17 AM
Extracting Data from xml file nishana Shell Programming and Scripting 3 07-13-2007 08:17 AM
Extracting data from an AFP file Dolph UNIX for Advanced & Expert Users 4 05-22-2007 05:29 AM

Closed Thread
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-18-2008
gugs gugs is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 44
Extracting data from a string containing &;

How can I exrtact the code HU52143N200401 from a string that contains >HU52143N200401<
  #2 (permalink)  
Old 07-18-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
One way:
Code:
sed 's/.*;.*;\([^&]*\)&.*/\1/g'
  #3 (permalink)  
Old 07-18-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Using cut

Code:
> echo ">HU52143N200401<" | cut -d";" -f3 | cut -d"&" -f1
HU52143N200401
  #4 (permalink)  
Old 07-18-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
That's unfair! Mine was looking more complicated!
  #5 (permalink)  
Old 07-18-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,431
Code:
awk -F'[&|;]' '{print $4}'
  #6 (permalink)  
Old 07-18-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,887
Well, in this case, with bash, zsh(with ^ instead of !) and ksh93:

Code:
% s='>HU52143N200401&lt'
% printf "%s\n" "${s//[!A-Z0-9]}"
HU52143N200401
  #7 (permalink)  
Old 07-18-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,431
Or just tr
Code:
tr -d '[:punct:][a-z]'
Closed Thread

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 09:57 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