Remove certain column with numeric value | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Remove certain column with numeric value

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-26-2013
radius radius is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 30 September 2014, 5:21 AM EDT
Posts: 90
Thanks: 38
Thanked 0 Times in 0 Posts
Remove certain column with numeric value

I have file1.txt


Code:
LBP298W2,300,-18,-115,-12,-105
LBP298W2,300,-18,-115,LBP298W3,300
LBP298W3,300,-18,-115,-12,-105

---------- Post updated at 03:35 AM ---------- Previous update was at 03:34 AM ----------

i want to remove every line with non numeric value in column 5

expected result


Code:
LBP298W2,300,-18,-115,-12,-105
LBP298W3,300,-18,-115,-12,-105

Sponsored Links
    #2  
Old 03-26-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 30 September 2014, 1:08 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,233
Thanks: 121
Thanked 453 Times in 412 Posts
Can try if this is sufficient:

Code:
$ awk -F, '$5 !~ /[a-zA-Z]/' infile
LBP298W2,300,-18,-115,-12,-105
LBP298W3,300,-18,-115,-12,-105

Sponsored Links
    #3  
Old 03-26-2013
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 30 September 2014, 8:27 AM EDT
Location: San Jose, CA, USA
Posts: 4,760
Thanks: 181
Thanked 1,588 Times in 1,352 Posts
If zaxxon's proposal isn't sufficient for your purposes, this is more precise:

Code:
awk -F, '$5 ~ /^[-+]?[[:digit:]]+$/' file1.txt

    #4  
Old 03-26-2013
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 26 September 2014, 7:14 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,674
Thanks: 182
Thanked 620 Times in 578 Posts
With Perl (core modules):


Code:
perl -F, '-MScalar::Util qw(looks_like_number)' -lane'
  print if looks_like_number $F[4]
  ' infile

Sponsored Links
    #5  
Old 03-26-2013
radius radius is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 30 September 2014, 5:21 AM EDT
Posts: 90
Thanks: 38
Thanked 0 Times in 0 Posts
so much thank you...mr Zax, Don,& Radoulov
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sorting file based on a numeric column Homa Shell Programming and Scripting 4 10-23-2012 09:55 AM
How to remove numeric characters in the flat file rafimd1985 UNIX for Dummies Questions & Answers 4 03-03-2012 11:02 PM
How to check if a column is having a numeric value or not in a file? keerthan Shell Programming and Scripting 9 04-04-2010 11:53 AM
Remove non numeric values from a variable ownedthawte Shell Programming and Scripting 13 03-31-2009 11:47 AM
to remove space after numeric ali560045 Shell Programming and Scripting 2 09-17-2008 05:23 AM



All times are GMT -4. The time now is 11:51 AM.