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.

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 11-13-2006
test_1234 test_1234 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 2
Regarding awk

Hi ,
In shell script I wrote:
awk '$1 == "name" {print $2 }' /home/test/name.log

means in that file if first word is "name" than I print second word.
Problem is :
sometimes in that file , first word is "name" nothing is there as second word.
Actual name is in the next line as second word.

means if $2 is null i want third word in next line.

How to handle this situation
  #2 (permalink)  
Old 11-13-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Try:

Code:
awk '$1 == "name" {if ($2 != "")
                     print $2 
                     else
                        {
                        getline
                        print $3
                        } 
                  }' /home/test/name.log

Regards.
  #3 (permalink)  
Old 11-13-2006
test_1234 test_1234 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 2
Thanks a lot
It is working fine
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 06:03 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