|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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 " } ' inputfileTry that |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Code:
awk ' { if(!(($3 >= 10 && $3 <= 180) || ($3 == 0))) print; } ' input_file |
|
#4
|
||||
|
||||
|
Code:
awk 'NF!=3 || $NF ~ /^([1-9]|-)$/' file |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Code:
awk ' { if(!(($3 >= 10 && $3 <= 180) || ($3 == 0))) print; } ' input_fileCode:
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
|
|||
|
|||
|
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 JFHFJFJF6Last edited by Franklin52; 11-20-2012 at 02:38 AM.. Reason: Please use code tags for data and code samples |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
thanks guys but how can i give error massage
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|