The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
select a record from one file matching from second file using awk synmag Shell Programming and Scripting 7 06-11-2008 11:37 PM
how to read record by record from a file in unix raoscb UNIX for Dummies Questions & Answers 1 05-16-2008 03:30 AM
Script to search a bad record in a file then put the record in the bad file shilendrajadon UNIX for Advanced & Expert Users 1 12-28-2007 07:00 AM
splitting a record and adding a record to a file rsolap Shell Programming and Scripting 1 08-13-2007 10:58 AM
how to delete record in file data with index in another file? zhynxn Shell Programming and Scripting 0 07-05-2006 09:03 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-28-2007
Registered User
 

Join Date: Dec 2007
Posts: 3
Thumbs down Script to search a bad record in a file then put the record in the bad file

I need to write a script that can find a bad record (for example: there is date field colom but value provided in the file for this field is N/A) then script shoud searches this pattern and then insert the whole record into the bad file.

Example:

File1

Name designation dateOfJoining
Shilendra SE 12/28/2007
Brijesh SE 12/25/2007
Sunil JSE N/A
Pankaj SE 12/20/2007
Manish SE N/A
Akhilendra SE 11/20/2007

Then after running the script the file should be like

File1

Name designation dateOfJoining
Shilendra SE 12/28/2007
Brijesh SE 12/25/2007
Pankaj SE 12/20/2007
Akhilendra SE 11/20/2007

And bad file will contain the record for which date was N/A

BadFile

Name designation dateOfJoining
Sunil JSE N/A
Manish SE N/A

Pls help me out as soon as possible.

Thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 12-28-2007
Moderator
 

Join Date: Feb 2007
Posts: 2,317
You can use grep, check the manpage.

Regards
Reply With Quote
  #3  
Old 12-28-2007
Klashxx's Avatar
HP-UX/Linux/Oracle
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 383
Code:
awk '{print > ( $3=="N/A" ) ? "bad_file" : "tmp" }' file1
mv tmp file1
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0