Script to check field value from a file records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to check field value from a file records
# 8  
Old 05-03-2018
Moderator's Comments:
Mod Comment Your continued refusal to use CODE tags (as required by the rules you agreed to when you joined this forum) may lead to you be placed in a read-only state or being permanently banned from from this site.

Please review the rules you agreed to when you joined this forum and start formatting your posts correctly on your own instead of expecting administrators and moderators to format your posts for you.
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 05-04-2018
Some unmatched record in output

HI,

I used below script but its also include some record which not matched with any condition as given in first post.


Code:
Record1|Record2|Record3|Record4|Record5|DATE1|DATE2

1024093815|000062317748|002F96B6|95|649|07052018|03052018

1032569624|000054060884|00E10177|189|1060|08052018|03052018

Code:

Code:
awk -F\| '
NR > 1  {for (i=1; i<=3; i++) if (!$i)  {print; next}
         if ($4   == "")        {print; next}
         if ($5+0 <= 0)         {print; next}
         for (i=6; i<=7; i++) if (!($i ~ /[0-3][0-9][01][0-9]20[12][0-9]/))     {print; next}
        }
'


Moderator's Comments:
Mod Comment You're in a two day read-only ban as you - despite intense warnings and reminders - repeatedly didn't use CODE tags as required by forum rules!

Last edited by RudiC; 05-04-2018 at 05:32 PM.. Reason: Added CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

2. Web Development

Javascript to check field is empty then execute rest of script

I have found this bit of code that nearly does what I want. Basically 3 input fields, I want to copy t2 to t3 as it's typed but only if t1 contains data AND t3 is empty: <input type="text" id="t1" /> <input type="text" id="t2" /> <input type="text" id="t3" /> <script> var t2 =... (4 Replies)
Discussion started by: barrydocks
4 Replies

3. Shell Programming and Scripting

Read File and check records for length

I need a script that will run in unix to: 1) Read and input file with 1 column that contains for ex: 0123456789 1234567890 ...etc 2) Checks the first column if it is: a. Numeric from 0 - 9 b. if it is not less... (4 Replies)
Discussion started by: mrn6430
4 Replies

4. Shell Programming and Scripting

Extract file records based on some field conditions

Hello Friends, I have a file(InputFile.csv) with the following columns(the columns are pipe-delimited): ColA|ColB|ColC|ColD|ColE|ColF Now for this file, I have to get those records which fulfil the following condition: If "ColB" is NOT NULL and "ColD" has values one of the following... (9 Replies)
Discussion started by: mehimadri
9 Replies

5. Shell Programming and Scripting

Replace a particular field in all records in a csv file

hi, i have various csv files, the file format is as follows Entry: "1",4,2010/08/15-10-00-00.01,,"E",,,,,,,,,120,0,"M4_","C","KEW-011-5337140-20100916163456-540097","1234567890","N N 0 ",,,"NUK 800100200",,,"NN",,,,,,,,,,,,"0000000001|0001|20150401... (2 Replies)
Discussion started by: niteesh_!7
2 Replies

6. Shell Programming and Scripting

How to check field formatting of input file?

Hi, I had input file with below data, abcdefghij;20100903040607;1234567891;GLOBAL; Having values of fields with seperated by semi-colon (;) and ended with line feed (\n). Through shell script, how can I check the field formatting? Thanks in advance. (18 Replies)
Discussion started by: Poonamol
18 Replies

7. Shell Programming and Scripting

simplify the script, check field match to value in a file

Hi Everyone, Below is the script, i feel there should be more simple way to do the same output, my one works, but feel not nice. like using index i feel it is slow (image my file is very large), maybe awk can do one line code? Please advice. # cat 1.txt 1 a 2 b 3 cc 4 d # cat 1.pl... (6 Replies)
Discussion started by: jimmy_y
6 Replies

8. Shell Programming and Scripting

how to check if a file has zero records

I want to do conditional logic on whether a file has 0 bytes or more than 0 bytes. what is the easiest way to do this? (2 Replies)
Discussion started by: guessingo
2 Replies

9. Shell Programming and Scripting

Based on num of records in file1 need to check records in file2 to set some condns

Hi All, I have two files say file1 and file2. I want to check the number of records in file1 and if its atleast 2 (i.e., 2 or greater than 2 ) then I have to check records in file2 .If records in file2 is atleast 1 (i.e. if its not empty ) i have to set some conditions . Could you pls... (3 Replies)
Discussion started by: mavesum
3 Replies

10. Shell Programming and Scripting

Check valid records in really big file with one commend..

Hi, I have a 5 gig file, no record terminators, field terminators are newline. The record length is 768 and I would like to check that every 768th byte is a newline and print out the byte position if it isn't. I would like to do this going either forward or backwards with one command if... (3 Replies)
Discussion started by: vtischuk@yahoo.
3 Replies
Login or Register to Ask a Question