LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Reply
 
Search this Thread
Old 12-15-2008, 07:11 AM   #1
mcandy
LQ Newbie
 
Registered: Mar 2004
Posts: 12

Rep: Reputation: 0
awk , I need help for awk, just a display function


Hello Guys,
I have a text file in which I would like to get a print of a certain parm and a parm of the next text line.
Here an example for my input file:
----------------------------------------------------- one record
1.1.1.1
Care of Addr 1.1.1.2
Lifetime granted 01:00:00 (3600), remaining 00:28:34
Flags sbdmg-T-, Identification CCF0CC61.57FA6D4
Tunnel src 1.1.1.3 dest 1.1.1.4 reverse-allowed
-----------------------------------------------------
I have a lot of that inputs (records) in one file with different IP addresses
- so I need to filter for the ip e.g. "1.1.1.1"
- thank I would like to get the the IP of the second line, which is "1.1.1.2"

I don't know how to use awk to grep for something and than how to get a {print $4} of the second line?

thanks in advance!
 
Old 12-15-2008, 12:21 PM   #2
jantman
Member
 
Registered: Nov 2005
Location: New Jersey, USA
Distribution: SuSE
Posts: 492

Rep: Reputation: 31
Personally, I might consider doing this in a scripting language, as it looks like it could get a bit complex. Also, the format is pretty clunky... is every record 5 lines in the same order, separated by that "----------------"? Something like CSV would be so much nicer...

i.e. how much heavy parsing do you need to do, and how much can you do by just pulling each record out of the file and then using grep or head/tail and awk?

Specific to your question - awk doesn't grep for something. grep greps for something. I'm sure there are conditionals in awk, but I've never used them. The ideal way I would do this, if the file is fixed-format, is to used sed to replace every newline with a space and replace every one of those "-----------" with a newline, ending up with one record per line. then just use awk to print the right fields.
 
  


Reply


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
Is there a function similar to awk for C++? binarybob0001 Programming 12 06-16-2011 04:43 PM
awk sort function not sorting from lowest to highest. skuz_ball Programming 4 08-09-2008 12:20 AM
How to use split function with AWK command? intikhabalam Linux - General 4 07-29-2008 10:40 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
Need help with awk function philosophia Programming 1 02-20-2007 05:53 PM


All times are GMT -5. The time now is 04:11 PM.

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