The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix File Validation! Help minnuverma Shell Programming and Scripting 8 10-24-2008 08:46 AM
validation required in unix u263066 UNIX for Dummies Questions & Answers 2 09-25-2008 04:37 AM
UNIX script Validation matchey Shell Programming and Scripting 1 05-07-2008 12:56 PM
How Can I Do Time Validation in UNIX mosammey UNIX for Dummies Questions & Answers 4 11-26-2007 12:02 PM
Time Validation in UNIX? mosammey Shell Programming and Scripting 1 11-21-2007 02:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-23-2008
minnuverma minnuverma is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 6
Unix File Validation! Help

Hi All,

I got a file with 3 fields delimited by hyphen "-". I have to validate & cleanse the data before i begine the processing

Requirements

1. No record should contain more than 2 delimiters
2. No record should even contain less than 2 delimiters
3. Any records that matches rule 1 & 2 should be captured to
bad_records.dat
4. Delete records satisfying rules 1 & 2 from original incoming data file


Sample Format

input.dat
COL1-COL2-COL3
scott-2000-10
tiger-1000-20
c-bill-1000-30
mike20-1000

so after the validation&cleansing process, the data should appear like below

input.dat
scott-2000-10
tiger-1000-20

bad_records.dat
c-bill-1000-30
mike20-1000

Please note i can't use perl progressive scanning. I need to achieve this via korn shell script


Thanks guys
  #2 (permalink)  
Old 10-23-2008
nitin's Avatar
nitin nitin is offline
Registered User
  
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 88
Just curious, is this homework?
Anyhow, look in to awk. I've always found awk as my good friend.

-Nitin
  #3 (permalink)  
Old 10-23-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Thread closed

No double, or triple posting of questions.

The UNIX and Linux Forums - Forum Rules
  #4 (permalink)  
Old 10-23-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,800

Code:
for inputfile in *.dat
do
awk ' {good=sprintf("%s.%s", FILENAME, "good")
          bad=sprintf("%s.%s", FILENAME, "bad")
       if(NF==3) { print $0 > good} else {print $0 >bad}}'  $inputfile
done

you can add what you need to this liitle code fragment.
Closed Thread

Bookmarks

Tags
minnu, unix file validation

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0