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.

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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-18-2012
AraR87 AraR87 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 18 May 2015, 1:55 AM EDT
Posts: 50
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.Linux

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 Unix and Linux 12-18-2012
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 28 May 2015, 11:09 AM EDT
Location: NM
Posts: 10,454
Thanks: 337
Thanked 861 Times in 800 Posts

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

Sponsored Links
    #3  
Old Unix and Linux 12-18-2012
AraR87 AraR87 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 18 May 2015, 1:55 AM EDT
Posts: 50
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 Unix and Linux 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 Unix and Linux 12-18-2012
AraR87 AraR87 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 18 May 2015, 1:55 AM EDT
Posts: 50
Thanks: 1
Thanked 2 Times in 2 Posts
Cool. Thank you Linux
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
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 12:08 PM.