The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
select a record from one file matching from second file using awk synmag Shell Programming and Scripting 7 06-12-2008 02:37 AM
how to read record by record from a file in unix raoscb UNIX for Dummies Questions & Answers 1 05-16-2008 06:30 AM
Script to search a bad record in a file then put the record in the bad file shilendrajadon Shell Programming and Scripting 2 12-28-2007 10:02 AM
splitting a record and adding a record to a file rsolap Shell Programming and Scripting 1 08-13-2007 01:58 PM
how to delete record in file data with index in another file? zhynxn Shell Programming and Scripting 0 07-06-2006 12:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-28-2007
shilendrajadon shilendrajadon is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 3
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.
  #2 (permalink)  
Old 12-28-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
Code:
awk 'NR==1{print>(FILENAME".bad")}
{print>($3=="N/A"?FILENAME".bad":FILENAME".fixed")}' data
Use nawk or /usr/xpg4/bin/awk on Solaris.
Sponsored Links
Closed Thread

Bookmarks

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 08:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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