LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-01-2018, 02:56 PM   #1
vivekn1980
LQ Newbie
 
Registered: Nov 2017
Posts: 14

Rep: Reputation: Disabled
a script required to check field value from a file records.


I need a script to check the records in a file , if any value match transfer the record in error.txt file.


1- If any of the any field value is NULL(nothing in this field)

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

Example:

11111111|22222222|NULL|12|444|27042018|27042018 (Record3 is null)

99999999|88888888|007172FD|NULL|975|02052018|27042018 (Record4 is null)


2- If any of the field value is set as 0, except Record4

Example:

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

Record1 = 0 or ‘00000000’
Record2 = 0 or ‘0000000000’
Record3 = 0 or ‘0000000000’

11111111111|000080809643|00000000|64|374|02052018|27042018
11111111111|000000000000|45678987|64|374|02052018|27042018
0000000000|000082079914|0071170B|1|308|27042018|27042018


4- If Record5 value is negative

11111111111|000045672345|45678987|64|-222|02052018|27042018

Last edited by vivekn1980; 05-08-2018 at 12:02 PM.
 
Old 05-01-2018, 05:45 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Given the tags you assigned, I'd leave out bash.
So, what efforts have you made yourself ?.
 
1 members found this post helpful.
Old 05-01-2018, 06:52 PM   #3
vivekn1980
LQ Newbie
 
Registered: Nov 2017
Posts: 14

Original Poster
Rep: Reputation: Disabled
awk command

I tried below given awk command but no success

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}
}
' file > error.txt
 
Old 05-02-2018, 12:15 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
That's one way of doing it.
If you are not getting what you expect, put some diagnostic (extra) prints in to see value of things you are testing - or not.
Diagnostics 101.

There are some obvious areas of potential concern - how many records are you passing in ?. The string "NULL" is not null ...
 
Old 05-03-2018, 12:25 PM   #5
vivekn1980
LQ Newbie
 
Registered: Nov 2017
Posts: 14

Original Poster
Rep: Reputation: Disabled
Check date format

i use following awk command:

awk -F'|' -v OFS='|' ' $6 !~ "^(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[12])[0-9]{4}$" || $7 !~ "^(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[12])[0-9]{4}$" '



but its not matching the date for given record:

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

108899999|0000222222|00AAAAA|-228|60|29102017|27042018


if DATE1 having 10th month its not matched with awk script.

Last edited by vivekn1980; 05-03-2018 at 03:14 PM.
 
Old 05-03-2018, 05:20 PM   #6
vivekn1980
LQ Newbie
 
Registered: Nov 2017
Posts: 14

Original Poster
Rep: Reputation: Disabled
Working now

Thanks , i use following awk command to check date format DDMMYYYY, it works:

awk -F'|' -v OFS='|' ' $6 !~ "^(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[012])((19|20)[0-9][0-9])$" || $7 !~ "^(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[012])((19|20)[0-9][0-9])$"'
 
  


Reply

Tags
awk, bash, perl, python, scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to match different records based on Same Field values using awk Abdelrahman.fathy Programming 22 11-11-2015 10:32 PM
linux login check script required mohit75 Programming 2 09-24-2013 12:24 AM
[PHP] [mySQL] Finding all records with with a certain field. s0l1dsnak3123 Programming 2 06-15-2008 08:26 PM
How to insert same text in one field for 10,000 records table edhan Linux - Newbie 6 06-13-2005 03:48 AM
How to check which package provide a required missing file? davidas Linux - Newbie 4 08-10-2004 12:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration