The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find and replace javeed7 Shell Programming and Scripting 1 04-02-2008 06:00 AM
find and replace mahabunta UNIX for Dummies Questions & Answers 7 09-21-2006 09:05 AM
find and replace valhutch UNIX for Dummies Questions & Answers 4 07-29-2006 02:20 PM
find and replace vikas_j@hotmail UNIX for Dummies Questions & Answers 3 02-25-2002 02:41 PM
Find & Replace gagansharma Shell Programming and Scripting 3 11-27-2001 01:17 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-06-2008
Registered User
 

Join Date: Apr 2008
Posts: 9
Find and replace

Hi,
I am trying to do this find and replace in unix and somehow its not working.

Quote:
nawk -F'|' 'NF != 8 {printf "%s||\n", $0 }' catman_852_header.txt>header
nawk -F'|' 'BEGIN{OFS="|";}{ if ($9 != "CC"){$9="CC";} print }' header>header1
TR|20080325|22952 |000000040|20080327|0530
TR|20080417|23078 |000000104|20080418|0530|1040001 |

I have the records coming in the above format. My requirement is if delimiter count is not 8 then put in the missing 2 delimiters. THen at the end of the file place CC.
This one fails when at position 8 I get some data. ITs inserting
TR|20080417|23078 |000000104|20080418|0530|1040001 | CC||

I dont want those 2 extra delimiters at the end. IT should be

TR|20080417|23078 |000000104|20080418|0530|1040001 | CC.
TR|20080325|22952 |000000040|20080327|0530||CC.

Can anyone please help me out.

Thanks
Kiran
Reply With Quote
Forum Sponsor
  #2  
Old 05-06-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,931
Something like this?
(use nawk or /usr/xpg4/bin/awk on Solaris)

Code:
awk 'NF=8{$NF=$NF"CC"}1' FS=\| OFS=\| file
Reply With Quote
  #3  
Old 05-06-2008
Registered User
 

Join Date: Apr 2008
Posts: 9
awesome!!
it worked
THanks
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 08:14 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