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    
 
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: 11 July 2016, 10:26 PM EDT
Posts: 132
Thanks: 50
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: 27 September 2016, 9:52 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,479
Thanks: 157
Thanked 526 Times in 462 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 online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 27 September 2016, 11:19 PM EDT
Location: San Jose, CA, USA
Posts: 9,378
Thanks: 430
Thanked 3,148 Times in 2,700 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 Advisor  
Forum Adviser
 
Join Date: Jan 2007
Last Activity: 16 December 2015, 5:59 AM EST
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 628 Times in 585 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: 11 July 2016, 10:26 PM EDT
Posts: 132
Thanks: 50
Thanked 0 Times in 0 Posts
so much thank you...mr Zax, Don,& Radoulov
Sponsored Links
Closed

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 11:27 PM.