Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete empty space at specific column 2

Status
Not open for further replies.

dbase77

Technical User
Apr 23, 2002
591
IE
Hi All,

If anybody could help me with my scenario here. I have a statement file. Example of some content:
Code:
     DATE          DESC     Debit    Credit  Total     Rate
    02-Jan-08   Lodgement   200.00          1200.00    2.51
    14-Sep-07   Withdrawal           50.00  1000.00    2.51
    29-Oct-06   Lodgement   100.00          1050.00    2.51
What I want to do here is to remove couple of empty spaces between column Total and Rate. Any lines that start with date (eg. as date above 02-Jan-08,14-Sep-07,29-Oct-06), I want to remove lets say 2 empty spaces between Total value and Rate value. Date always starts after 8 spaces. Can this be done with sed or awk? I'm totaly lost here. At the moment the Rate value is out of the box (special statement paper).

Thanks.
 
Something like this should do it:

Code:
cut -c1-51,55- inputfile > outputfile

That's a pretty cramped piece of paper, let's hope no-one deposits 100,000.00! Or that interest rates go into double-digits...


Annihilannic.
 
Very simple. But how do I go about doing it in every first occurrence of date after 8 white spaces? The statement itself has header and footer. Basically I need the header and footer untouch and only delete 2 spaces between Total column and Rate column.

Thanks again.
 
Of course, there would be other data on the statement... how come there aren't 8 spaces before them in the sample data you pasted?

Here's something that works for the sample data you posted, you'll need to adjust the number of spaces for the real data:

Code:
awk '[green]/^    ([0-9][0-9]-[A-Z][a-z][a-z]-[0-9][0-9]| DATE) /[/green] { [b]print[/b] [b]substr[/b]([blue]$0[/blue],1,51) [b]substr[/b]([blue]$0[/blue],55); [b]next[/b] } 1' inputfile > outputfile

Annihilannic.
 
This is very very good. Very impressive.

Could you explain why you have '|' to DATE and number '1' after 'next', please? Just want to fully understand what it does. And what is '$0' use for?

Thanks again.
 
The | in this case is not a pipe, it signifies alternation (i.e. OR logic) in the regular expression. In other words, execute the following code if the input line is the header containing "DATE" or a line beginning with a date matching dd-Mmm-yy.

$0 contains the entire input line.

1 is just a shortcut to print all the other input lines without any processing. awk's default behaviour for every expression { code } pair is to print out the line if the expression evaluates to true (or a non-zero number) if no { code } is supplied.

Alternatively you could replace it with just { print }... i.e. some code with no expression, in which case the code is executed for every input line.

Annihilannic.
 
arghhh, I hate this statement file. Now I need to add few whitespaces between 'Credit' and 'Total' value. What do I need to add to above code? I dont mind running seperate command though.

Thanks again.
 
You should be able to figure it out from what you've got already... just break it into three substrings instead of 2, and insert a " " between them somewhere.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top