Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Remove certain column with numeric value

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-26-2013
radius radius is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 20 July 2015, 9:58 AM EDT
Posts: 124
Thanks: 49
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 Unix and Linux 03-26-2013
zaxxon's Unix or Linux Image
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 28 July 2015, 2:30 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,310
Thanks: 135
Thanked 469 Times in 423 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 Unix and Linux 03-26-2013
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 28 July 2015, 3:28 AM EDT
Location: San Jose, CA, USA
Posts: 6,794
Thanks: 289
Thanked 2,270 Times in 1,941 Posts
If zaxxon's proposal isn't sufficient for your purposes, this is more precise:

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

    #4  
Old Unix and Linux 03-26-2013
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 23 April 2015, 3:05 PM EDT
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 626 Times in 584 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 Unix and Linux 03-26-2013
radius radius is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 20 July 2015, 9:58 AM EDT
Posts: 124
Thanks: 49
Thanked 0 Times in 0 Posts
so much thank you...mr Zax, Don,& Radoulov
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 06:22 AM.