Check input file with different criteria | 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 input file with different criteria

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-19-2012
pareshkp pareshkp is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 22 July 2014, 11:30 AM EDT
Posts: 77
Thanks: 36
Thanked 1 Time in 1 Post
Check input file with different criteria

HI

Input file.txt


Code:
ABCDE1 JFHFJFJF3 10 
ABCDE2 JFHFJFJF5 20 
ABCDE3 JFHFJFJF5 30 
ABCDE4 JFHFJFJF6 -
ABCDE5 JFHFJFJF6 20
ABCDE6 JFHFJFJF6 90
ABCDE7 JFHFJFJF6 9
ABCDE8 JFHFJFJF6


I want to check third column if data missing or wrong data the echo massage and out from script.

1. all three column must have data.
2. Third column have value between 0 or 10 to 180 but not (1,2,3,4,5,6,7,8,9)
3. Third column not be blank


Output;


Code:
Script have error in Below Line 

ABCDE4 JFHFJFJF6 -
ABCDE7 JFHFJFJF6 9
ABCDE8 JFHFJFJF6 

Please verify your input and run the script again

Sponsored Links
    #2  
Old 11-19-2012
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 22 July 2014, 2:33 PM EDT
Location: NM
Posts: 10,152
Thanks: 267
Thanked 780 Times in 730 Posts

Code:
awk ' BEGIN{print "Script have error in Below Line" ; bad=0}
       { ok=0
          ok=(NF==3)?1:0
          if(ok)   {ok=($(NF)==0 || ($(NF)<=100 && $(NF)>=10)?1:0}
          if(!ok} {print $0; bad++}
          next;
        }
          END 
         {print (bad==0) ? "no errors found" : 
                         "Please verify your input and run the script again " } ' inputfile

Try that
Sponsored Links
    #3  
Old 11-19-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 July 2014, 1:20 PM EDT
Location: Galactic Empire
Posts: 3,354
Thanks: 230
Thanked 1,190 Times in 1,123 Posts

Code:
awk ' { if(!(($3 >= 10 && $3 <= 180) || ($3 == 0))) print; } ' input_file

    #4  
Old 11-19-2012
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Gotham Knight
 
Join Date: Mar 2012
Last Activity: 16 July 2014, 3:22 PM EDT
Location: India
Posts: 1,412
Thanks: 100
Thanked 495 Times in 472 Posts

Code:
awk 'NF!=3 || $NF ~ /^([1-9]|-)$/' file

Sponsored Links
    #5  
Old 11-19-2012
pareshkp pareshkp is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 22 July 2014, 11:30 AM EDT
Posts: 77
Thanks: 36
Thanked 1 Time in 1 Post

Code:
awk ' { if(!(($3 >= 10 && $3 <= 180) || ($3 == 0))) print; } ' input_file


Code:
awk 'NF!=3 || $NF ~ /^([1-9]|-)$/' file

Both script are good but i want to stop the script and give error massage ...
Sponsored Links
    #6  
Old 11-19-2012
subramanian subramanian is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 10 November 2013, 4:55 AM EST
Posts: 9
Thanks: 0
Thanked 2 Times in 2 Posts
you can try this..

Code:
nawk ' ( ($1!~/[A-Za-z0-9]/ || $2!~/[A-Za-z0-9]/ || $3!~/[A-Za-z0-9]/ ) || ( $3==0 || ( ($3<10 && $3>180) || ($3>=1 && $3<=9) ))) { print $0 }' InputFile.txt
ABCDE4 JFHFJFJF6 -
ABCDE7 JFHFJFJF6 9
ABCDE8 JFHFJFJF6


Last edited by Franklin52; 11-20-2012 at 02:38 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #7  
Old 11-19-2012
pareshkp pareshkp is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 22 July 2014, 11:30 AM EDT
Posts: 77
Thanks: 36
Thanked 1 Time in 1 Post
thanks guys but how can i give error massage
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
Input file check Krrishv Shell Programming and Scripting 1 08-02-2011 02:03 AM
shell script to take input from a text file and perform check on each servers and copy files joseph.dmello Shell Programming and Scripting 0 02-04-2011 07:34 AM
How to check field formatting of input file? Poonamol Shell Programming and Scripting 18 09-29-2010 12:53 AM
Need to find a string, check the next line, and if it matches certain criteria, replace it with a s midniteslice Shell Programming and Scripting 6 11-16-2009 02:08 PM
check presence of input file newpromo Shell Programming and Scripting 4 10-01-2009 07:50 PM



All times are GMT -4. The time now is 03:34 PM.