Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-08-2012
Registered User
 

Join Date: Jan 2012
Posts: 10
Thanks: 10
Thanked 0 Times in 0 Posts
Delete row if a a particular column has more then three characters in it

Hi i have a data like


Code:
hw:dsfnsmdf:39843     chr2     76219829      51M        atatata   51    872389
hw:dsfnsmdf:39853     chr2     76219839      51M65T   atatata   51    872389
hw:dsfnsmdf:39863     chr2     76219849      51M        atatata   51    872389
hw:dsfnsmdf:39873     chr2     76219859      30M32X   atatata   51    872389


I want to dalete all the rows having more then 3 charecters in 4th coloumn

sample output

Code:
hw:dsfnsmdf:39843     chr2     76219829      51M        atatata   51    872389
hw:dsfnsmdf:39863     chr2     76219849      51M        atatata   51    872389

Can anyone help me out how to do this.
Thanks.

Last edited by joeyg; 02-08-2012 at 02:09 PM.. Reason: Please wrap examples and scripts with CodeTags
Sponsored Links
    #2  
Old 02-08-2012
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 

Join Date: Dec 2007
Location: 42.34699969120303°N by 71.09759330749512°W
Posts: 1,898
Thanks: 23
Thanked 75 Times in 69 Posts
Perhaps something like...


Code:
awk 'if (length($4)<=3) print $0 <datafile

You may need to add a delimiter, though. Unsure if spaces or tab or ?? between fields.

Last edited by joeyg; 02-08-2012 at 02:45 PM..
The Following User Says Thank You to joeyg For This Useful Post:
bhargavpbk88 (02-08-2012)
Sponsored Links
    #3  
Old 02-08-2012
Registered User
 

Join Date: Oct 2010
Posts: 14
Thanks: 5
Thanked 1 Time in 1 Post
Try this.


Code:
awk '{if (lenght($4)<=3) {print $0}}' datafile

The Following User Says Thank You to ezitoc For This Useful Post:
bhargavpbk88 (02-08-2012)
    #4  
Old 02-08-2012
Moderator
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 12,191
Thanks: 232
Thanked 1,703 Times in 1,632 Posts
You can reduce that:


Code:
awk 'length($4) <= 3' datafile

The Following User Says Thank You to Corona688 For This Useful Post:
bhargavpbk88 (02-08-2012)
Sponsored Links
Reply

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
SED help delete characters in a string redtred Shell Programming and Scripting 7 08-31-2011 07:46 AM
Removing last ten characters from a column e3r1ck_ETT UNIX for Dummies Questions & Answers 9 03-23-2009 04:20 PM
Delete not readable characters ajilesh Shell Programming and Scripting 3 12-14-2008 01:11 PM
how to delete M-^M characters from a file hyennah UNIX for Dummies Questions & Answers 1 11-20-2008 05:17 PM
Delete specific characters masquerer AIX 4 04-21-2008 05:00 AM



All times are GMT -4. The time now is 04:47 AM.