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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
DUNE (Numerics) 1.1 (Default branch) iBot Software Releases - RSS News 0 05-09-2008 03:20 AM
Count No of Records in File without counting Header and Trailer Records guiguy Shell Programming and Scripting 2 06-07-2007 09:15 AM
Conversion to display leading zeros for numerics dsimpg1 Shell Programming and Scripting 4 12-02-2005 07:43 PM
Drop Users trfrye UNIX for Dummies Questions & Answers 2 08-31-2005 12:39 PM
deleting records with a missing field gillbates UNIX for Dummies Questions & Answers 2 12-12-2002 07:52 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-14-2007
Registered User
 

Join Date: Aug 2007
Posts: 2
Stumble this Post!
Unhappy Drop records with non-numerics in field X

I have tab delimited file and need to remove all records prior to sort, that have non-numerics in the Field 2. valid/invalid field 2 data examples are:
" 123" valid
"1 23" invalid
" NOPE" invalid

I've tried this awk it does not recognize tab as the delimiter or check all characters in field 2:
awk -Ftab '$1 ~ /^[0-9]/ { print $1 }'<$ebs_filter_file

I've also played around with sed, but can't seem to get it. Any help would be appreciated!

akxeman
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-14-2007
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
Stumble this Post!
awk -F"\t" '$1 ~ /[a-z]/ { print $0 }' test
Reply With Quote
  #3 (permalink)  
Old 08-14-2007
Registered User
 

Join Date: Aug 2007
Posts: 2
Stumble this Post!
Thanks! Still having an issue with situations that contain both alpha & numeric characters such as "12A3" & "4 6" comes back as valid, when I want to drop them. Is there anything I can put in/around the expression to check all characters in the field?
Reply With Quote
  #4 (permalink)  
Old 08-14-2007
Registered User
 

Join Date: May 2007
Posts: 211
Stumble this Post!
Code:
awk -F"\t" '{if ($2 !~ /[A-Za-z ]/) {print $2 "\t valid"; } else {print $2 "\t invalid";}}' filename
Output
Code:
123      valid
1 23     invalid
123AB    invalid
ABD123   invalid
12345    valid
NOPE     invalid
1234     invalid
or if you want to drop those which are alphanumberic,try

Code:
awk -F"\t" '$2 !~ /[A-Za-z ]/ { print $0 }' filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0