Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-11-2008, 06:27 AM   #1
LQ Newbie
Registered: Mar 2008
Location: Johannesburg
Posts: 5

Rep: Reputation: 0
extracting field from line

I would like to extract a field from a log file,
eg: Backup|5.4.8 5.2.4|OK|Fri Aug 8 21:30:13 2008||2|11|01:53:46|92975371081/92975371081/1177124864|00:17:08:5b:fa:54|gnslnx|Linux5.2.4

the only field i need is after the first /
i.e 489c9ec5
I tried this :
tail -1 /LOG|awk -F"/" '{print $2}'
but get all extra stuff as well:

Any Help will be apreciated

Old 08-11-2008, 06:47 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
You specified "/" as the field separator, so you got everything between the first two instances of "/". So far, all is normal.

How about this?
awk -F "|" '{print $2}' filename | sed 's?.*/??'


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting line number s_shenbaga Linux - Newbie 1 10-21-2005 06:52 AM
Extracting a specific line from an ASCII file heyyou Programming 7 03-21-2005 05:19 PM
Extracting the line number in Unix Shell? Aziz Programming 2 12-01-2004 12:03 PM
extracting ms powerpoint template files (.pot) from the command line? fibbi Linux - Software 0 11-07-2004 05:27 PM
extracting line by line from a file sanjith11 Programming 3 07-02-2004 08:38 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:09 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration