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 > 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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Flat File in HP-UX Krishnaramjis Shell Programming and Scripting 0 06-03-2008 12:24 AM
Flat file Krishnaramjis Shell Programming and Scripting 9 05-08-2008 11:28 PM
Help with a Flat File!!! kumarsaravana_s Shell Programming and Scripting 11 06-08-2007 12:15 AM
XML to flat file balireddy_77 Shell Programming and Scripting 2 04-13-2007 06:57 AM
Converting Pivot file to flat file vskr72 Shell Programming and Scripting 2 10-18-2005 05:41 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 04-16-2007
kumarsaravana_s kumarsaravana_s is offline
Registered User
  
 

Join Date: Feb 2007
Location: Bangalore
Posts: 105
Help with a flat file!!!

Hi All,

I get a flat file everyday with some records being invalid.Some records come with less number '|'.I just want to add the missing '|'s ,So the it doesnt give an error insufficient fields while loading...There area total of 32 pipes in each record.

Input:
ASADASD |Y|B|SDFGDSDFD| | |0|-2000|N|N|Y|Y| |P|111 |000 |N|N|N|N|N|N|N|ADJS|N |M| |N|N|N|A|Y|RC
ADASDAS|N|E|FSGDFGDFFS| | |0|0|Y|Y|N|N|N|P|111 |0000 |
DSASA|N|E|SDGFDGD| | |0|0|Y|Y|N|N|N|P|1111 |000 |

DASAS |Y|E|DFGDF| | |0|0|N|-|N|N| |P|111 |000 |N|N|N|N|N|N|N|ADJS|N |O| |N| |N|A|N|RC

Output :

ASADASD |Y|B|SDFGDSDFD| | |0|-2000|N|N|Y|Y| |P|111 |000 |N|N|N|N|N|N|N|ADJS|N |M| |N|N|N|A|Y|RC
ADASDAS|N|E|FSGDFGDFFS| | |0|0|Y|Y|N|N|N|P|111 |0000 |||||||| || ||||||
DSASA|N|E|SDGFDGD| | |0|0|Y|Y|N|N|N|P|1111 |000 |||||||| || ||||||
DASAS |Y|E|DFGDF| | |0|0|N|-|N|N| |P|111 |000 |N|N|N|N|N|N|N|ADJS|N |O| |N| |N|A|N|RC

Your help here is really appreciated..

regards,
Kumar
  #2 (permalink)  
Old 04-16-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,872
With GNU Awk:

Code:
awk 'NF<33{NF=33}1' OFS="|" FS="|" inputfile
With nawk:

Code:
nawk 'NF<33{NF=33;$1=$1}1' OFS="|" FS="|" inputfile

Last edited by radoulov; 04-16-2007 at 08:11 AM..
  #3 (permalink)  
Old 04-16-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
perl -aF"\|"  -lne ' print $_ . "|" x ( 31 - $#F ) ; ' file
  #4 (permalink)  
Old 04-16-2007
kumarsaravana_s kumarsaravana_s is offline
Registered User
  
 

Join Date: Feb 2007
Location: Bangalore
Posts: 105
Quote:
Originally Posted by anbu23
Code:
perl -aF"\|"  -lne ' print $_ . "|" x ( 31 - $#F ) ; ' file
Thanks a lot Anbu and radoulov...
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 09:00 AM.


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