wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes Extracting pattern only with AWK or SED Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Extracting pattern only with AWK or SED " Watch "Extracting pattern only with AWK or SED " New topic
Author

Extracting pattern only with AWK or SED

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
We have the following statement working, but when we move the program to Solaris 10 it fails.



How can we use AWK or SED to extract only the 6 digit number from the string?

The following outputs the entire string. We only want the 6 digit number.




Thanks.
[ August 21, 2008: Message edited by: James Clark ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

James,
Take a look at the print section of this tutorial. It shows how to use the longer form of awk to just print out a specific argument. The short form that you are using prints out the whole line.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Thank you much.

Below are sed commands that do the trick.



Or

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extracting pattern only with AWK or SED
 
Similar Threads
Making multiple files from single file
Calling awk script inside shell script
using sed to chnage data in file
Column number of a search pattern
regular expression