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 10-27-2008
Bandit390 Bandit390 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 19
Help with awk

I want to search $2 to see if the first letter contains W or the second letter contains W, but my code prints out nothing.

This is sample data from dataFile.txt

Code:
northwest NW Joel Craig 3.0 .98 3 4
western WE Sharon Kelly 5.3 .97 5 23
southwest SW Chris Foster 2.7 .8 2 18

Code

Code:
nawk '{ if (($2 == "W.") || ($2 == ".W")) print $2, $3, $4, $1}' dataFile.txt

When I specify ($2 == "NW") I get a print out of the line containing "NW", but when using the symbol to match any character....ex. ($2 == ".W"), I don't get anything.

Help!
Thanks
  #2 (permalink)  
Old 10-27-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915

Code:
$ nawk '$2 ~ /^.?W/ { print $2, $3, $4, $1 }' infile
NW Joel Craig northwest
WE Sharon Kelly western
SW Chris Foster southwest

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 03:32 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