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
To remove new line character shihabvk UNIX for Advanced & Expert Users 7 06-18-2009 07:44 AM
sed to remove character [' manishabh Shell Programming and Scripting 2 08-29-2008 11:28 PM
How to remove extraneous character vsmurali UNIX for Dummies Questions & Answers 7 03-18-2008 12:57 PM
Trying to remove single character from a line Iz3k34l UNIX for Dummies Questions & Answers 5 07-07-2007 01:29 PM
Remove Last Character of Line danhodges99 Shell Programming and Scripting 4 05-21-2003 09:30 AM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 10-06-2008
VPREATR VPREATR is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
Need to remove first character from every third line (or revised nawk).

Here's the data I'm starting with (example output of two combined queries, filesize: 284k)
Code:
3000877|555-55-1111|2|7/30/2008|TEST|P.O. BOX 1111|PALM DESERT|CA|92211||5555555555||||||||48|||1||1|3|||2|||||||||||||1|3||2|2
||||2||9||3|1|2|2|2|1|3|0||5|2|||||||||88||3|2||3|2||||2|1|||6|5/31/2008|2||||9|AD|||42|42||||||Y|555-55-1111|SMITH|JOHN|||12
/23/1960|2|WH|||||||||Y
3000178|555-55-1112|2|7/23/2008|TEST|P.O. BOX 1112|TEMECULA|CA|92591||5555555555||||||||33|||1||1|3|||2|||||||||||||3|3||2|
2||||2||9||2|1|2|2|2|2|3|0||5|2|||||||||88|||2||3|2||||2|9|||||2||||9|A|||42|42||||||Y|555-55-1112|SMITH|JACK|||12/8/1975|2|BL|
||||||||Y
3000317|555-55-1113|2|7/29/2008|TEST|P.O. BOX 1113|MORENO VALLEY|CA|92556||5555555555||||||||55|||1||4|1|||2|||||||||||||1|3||2|2||||
2||9||1|0|2|2|2|2|3|0||5|2|||||||||88|||2||3|2||||2|9|||||2||||9|A|||42|42||||||Y|555-55-1113|SMITH|JOE|||11/28/1953|2|AO|||||||
||Y
Then I run the following nawk script as a \n is needed after the #103 and #120 entries. (nawk -f scriptname > filename1)
Code:
[
BEGIN {
   FS="|"
       }
 
{
  OFS="|"
}
 
{
print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,
$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,
$41,$42,$43,$44,$45,$46,$47,$48,$49,$50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$60,
$61,$62,$63,$64,$65,$66,$67,$68,$69,$70,$71,$72,$73,$74,$75,$76,$77,$78,$79,$80,
$81,$82,$83,$84,$85,$86,$87,$88,$89,$90,$91,$92,$93,$94,$95,$96,$97,$98,$99,
$100,$101,$102,$103,"\n",
$104,$105,$106,$107,$108,$109,$110,$111,$112,$113,$114,$115,$116,
$117,$118,$119,$120,"\n"
}
END {}
The nawk script output (i.e. filename1) is:
Code:
3000877|555-55-1111|2|7/30/2008|TEST|P.O. BOX 1111|PALM DESERT|CA|92211||5555555555||||||||48|||1||1|3|||2|||||||||||||1|3||2|2
||||2||9||3|1|2|2|2|1|3|0||5|2|||||||||88||3|2||3|2||||2|1|||6|5/31/2008|2||||9|AD|||42|42||||||Y|
|555-55-1111|SMITH|JOHN|||12/23/1960|2|WH|||||||||Y|

3000178|555-55-1112|2|7/23/2008|TEST|P.O. BOX 1112|TEMECULA|CA|92591||5555555555||||||||33|||1||1|3|||2|||||||||||||3|3||2|
2||||2||9||2|1|2|2|2|2|3|0||5|2|||||||||88|||2||3|2||||2|9|||||2||||9|A|||42|42||||||Y|
|555-55-1112|SMITH|JACK|||12/8/1975|2|BL|||||||||Y|

3000317|555-55-1113|2|7/29/2008|TEST|P.O. BOX 1112|MORENO VALLEY|CA|92556||555555555||||||||55|||1||4|1|||2|||||||||||||1|3||2|2||||
2||9||1|0|2|2|2|2|3|0||5|2|||||||||88|||2||3|2||||2|9|||||2||||9|A|||42|42||||||Y|
|555-55-1113|SMITH|JOE|||11/28/1953|2|AO|||||||||Y|
The problem is on the third line of each entry, the nawk script has inserted an additional first character pipe (i.e. |) and it's causing a great deal of havoc given my import requirements. Now I've tried various sed methods of removal based on the first character of every 3rd line throughout the entire file, sadly without success. Lastly, I've revised the nawk script in attempt to exclude the additional pipe character, all without success.
Code:
|555-55-1113|SMITH|JOE|||11/28/1953|2|AO|||||||||Y|
It needs to be:
Code:
555-55-1113|SMITH|JOE|||11/28/1953|2|AO|||||||||Y|
Review, thoughts and suggestions are truly welcomed.

Thanks!
 

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 01:44 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