delete empty spaces at specific column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete empty spaces at specific column
# 1  
Old 01-18-2010
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:

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 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.
# 2  
Old 01-18-2010
Try cutting position 54 and 55 for instance:
Code:
cut -c-53,56- infile


Last edited by Scrutinizer; 01-18-2010 at 08:11 PM..
# 3  
Old 01-18-2010
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.
# 4  
Old 01-18-2010
Perhaps:
Code:
sed '/-/s/  */  /5' infile

# 5  
Old 01-18-2010
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.
# 6  
Old 01-18-2010
I think the structure your file is in the header you have extra tabs between date and description

assuming the field separator is tab

Code:
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
# 7  
Old 01-18-2010
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to delete empty files from specific locations

Hi, I need help in regard to developing a shell script to delete empty files from multiple specific locations. The directory paths will be stored in a text file. So the requirement is to read the text file for one specific path and then remove empty files from that particular path. Looping through... (4 Replies)
Discussion started by: Khan28
4 Replies

2. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

3. Shell Programming and Scripting

Delete column with exact string in specific col

Hi, my file structur looks like File structure looks: GeneID protein_gi Symbol 1246500 10954455 repA1 1246501 10954457 repA2 1246502 10954458 leuA But some of the cases do not have record for protein id. for example: 1343044 - orf01 I want to remove those rows. But I tried awk... (9 Replies)
Discussion started by: smitra
9 Replies

4. Shell Programming and Scripting

How to grep an empty line in a specific column of a file?

Suppose i have the following data : cat file.txt 12431,123334,55353,546646,14342234,4646,35234 123123,3535,123434,132535,1234134,13535,123534 123213,545465,23434,45646,2342345,4656,31243 2355425,2134324,53425,342,35235,23434,234535 3423424,234234,65465,,2344,35436,234524,234... (7 Replies)
Discussion started by: Ravi Tej
7 Replies

5. UNIX for Dummies Questions & Answers

Delete rows with unique value for specific column

Hi all I have a file which looks like this 1234|1|Jon|some text|some text 1234|2|Jon|some text|some text 3453|5|Jon|some text|some text 6533|2|Kate|some text|some text 4567|3|Chris|some text|some text 4567|4|Maggie|some text|some text 8764|6|Maggie|some text|some text My third column is my... (9 Replies)
Discussion started by: A-V
9 Replies

6. Shell Programming and Scripting

delete a row with a specific value at a certain column

Hi, I want to delete rows that have 0 at column 4. The file looks like this: chr01 13 61 2 chr01 65 153 0 chr01 157 309 1 chr01 313 309 0 chr01 317 469 1 chr01 473 557 0 I want to delete all rows with a 0 at column 4 chr01 13 61 2 chr01 157 309 1 chr01 ... (3 Replies)
Discussion started by: kylle345
3 Replies

7. Shell Programming and Scripting

delete lines with empty second column

hi, I'd like to ask you if you can help me with such surely easy thing - I have some data and need to plot them. I have txt of data in two columns, tab separated, but some second columns are empty. like 1```` 2 1.2`` 3```` 2 4.44` 5````` 6.1```1 how can I erase all the lines... (2 Replies)
Discussion started by: bsco
2 Replies

8. UNIX for Dummies Questions & Answers

Delete a specific column using vi editor?

Hello Experts, I'm a newbie so please excuse any wrong doings. I have a file that looks like this. abc def ghi jkl mno def abc ghi mno jkl ghi def mno jkl abc I would like the file to look like this abc def ghi jklmno def abc ghi mnojkl ghi def mno jklabc in other... (3 Replies)
Discussion started by: fnebiolo
3 Replies

9. Shell Programming and Scripting

Initializing empty string with spaces

Hi, I want to Initialize a String with 50 spaces. I can do that by ex: Var1=" " But i dont want to do in this way? Is there any unix command where i can specify no of spaces to a varaible? like space(50) (1 Reply)
Discussion started by: Shiv_18
1 Replies

10. UNIX for Dummies Questions & Answers

want to remove " in a file and delete empty spaces

I have to remove character " in file which occurs at every line and have to delete empty spaces. Please help (2 Replies)
Discussion started by: vikram2008
2 Replies
Login or Register to Ask a Question