Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions 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 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: 7 October 2016, 8:41 AM EDT
Posts: 53
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: 23 May 2017, 2:48 PM EDT
Location: NM
Posts: 11,065
Thanks: 526
Thanked 1,056 Times in 979 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: 7 October 2016, 8:41 AM EDT
Posts: 53
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: 15 November 2016, 10:59 PM EST
Posts: 269
Thanks: 2
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: 7 October 2016, 8:41 AM EDT
Posts: 53
Thanks: 1
Thanked 2 Times in 2 Posts
Cool. Thank you Linux
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
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 05:43 PM.