Check if the text file has more than 2 characters | 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.

Check if the text file has more than 2 characters

Shell Programming and Scripting


Tags
perl 5.8.8, unix alert script, unix commands, unix scripting

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-18-2012
AraR87 AraR87 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 9 July 2014, 8:05 AM EDT
Posts: 46
Thanks: 1
Thanked 2 Times in 2 Posts
Check if the text file has more than 2 characters

Guys,

I know that the below command will cut the 13th field from test.txt file

Code:
awk -F"|" '{print $13}' test.txt

The answer would be,

Code:
CA CN Ohio

If we see the 3 rd one, it has more than 2 characters. So i wanted to check this in if condition and i want to get the output if the 13th field has more than 2 characters.

Any help would be greately appreciated!!!

Last edited by Franklin52; 12-19-2012 at 02:20 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old 12-18-2012
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 25 October 2014, 4:18 AM EDT
Location: NM
Posts: 10,251
Thanks: 283
Thanked 803 Times in 747 Posts

Code:
awk -F'|'  'length($13)>2' inputfile > outputfile

Sponsored Links
    #3  
Old 12-18-2012
AraR87 AraR87 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 9 July 2014, 8:05 AM EDT
Posts: 46
Thanks: 1
Thanked 2 Times in 2 Posts
Thank you! Great...
It worked fine.. But this displaying the whole content..
Is there any way to display particular 13th field?
    #4  
Old 12-18-2012
bmk bmk is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 31 October 2013, 9:16 AM EDT
Posts: 262
Thanks: 1
Thanked 22 Times in 22 Posts
Try...

Code:
awk -F'|'  'length($13)>2 {print $13}' inputfile > outputfile

Sponsored Links
    #5  
Old 12-18-2012
AraR87 AraR87 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 9 July 2014, 8:05 AM EDT
Posts: 46
Thanks: 1
Thanked 2 Times in 2 Posts
Cool. Thank you
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
Any way to get rid of ^M characters in a text file using pr? Nonito84 UNIX for Dummies Questions & Answers 2 10-26-2011 05:44 PM
Help with deleting characters from text file evelibertine UNIX for Dummies Questions & Answers 1 06-28-2011 01:24 PM
How to check if the file has EBCDIC or ascii characters ahmedwaseem2000 Shell Programming and Scripting 1 07-02-2010 08:46 AM
Remove special characters from text file kkb Shell Programming and Scripting 10 12-07-2009 10:14 PM
Read text from a file between two characters.. goutam_igate Shell Programming and Scripting 2 04-16-2009 08:59 AM



All times are GMT -4. The time now is 04:35 PM.