delete empty spaces at specific column

Hi All,

If anybody could help me with my scenario here. I have a statement file. Example of some content:

     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 achieve 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). I want to put inside this special box. Hence I need o remove 2 spaces or perhaps more. Need to play around until get the right way.

Thanks.

Try cutting position 54 and 55 for instance:

cut -c-53,56- infile

Hi,

Thank you for replying.

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. If I use cut, then I'm going to lose some of the data. I need to delete 2 whitespaces on every line that starts with date. Example as above.

Thanks again.

Perhaps:

sed '/-/s/  */  /5' infile

Hmm. My data all over the places. I just want to remove 2 white spaces between Total and Rate value on every occurrence of date listed above.

Thanks anyway for replying.

I think the structure your file is in the header you have extra tabs between date and description

assuming the field separator is tab

awk -F "\t" '{if (/DATE/) {print $0} else {print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"  "$7} } ' abc.txt

Replace $6" "$7 with as many spaces needed

HTH,
PL

Hi,

No tab involve. Just plain spaces. I will try this code and get back to you. Probably it would work by looking at the code.

Thanks.

If tab is not involved then replace "\t" with the number of spaces present in the file

Please provide a sample that is representative for your actual data:

$ sed '/-/s/  */  /5' infile

     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