Solved

Removing tab from a column inside a file.

Posted on 2008-06-10
12
224 Views
Last Modified: 2010-04-22
Hi All,
I haveone file which has 100 records each separated by "|". In some records, one column has tab . How can i delete tab form that column inside a file.
example
20080609|67961856|EQUITY PARTNERS 2004 EMPLOYEE FUND, L.P       |EQUITY PARTNERS 2004 EMPLOYEE FUND, L.P        |

There is a tab after L.P.
I used sed 's/^[ \t]*//;s/[ \t]*$//' .. but this didnot help for tab between line.

Can Somebody Help?

0
Comment
Question by:sunilbains
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 21754391
sed 's/[ \t]*\|/|/g'
0
 

Author Comment

by:sunilbains
ID: 21754669
hi,
    iam getting following output..after tunning above command.
|2|0|0|8|0|6|0|9|||8|9|4|8|4|7|4|7|||M|a|t|s|u|m|o|i|n|c|.|||||P|r|i|v|a|t|e|P|l|a|c|e|m|e|n|t|||A|c|t|i|v|e|||2|0|0|3|0|1|2|0|||||0|.|0|0|||||||||||||||||||||||
I just need to remove "tab"  from records.
0
 
LVL 84

Expert Comment

by:ozo
ID: 21754735
which version of sed are you using?
sid you try it without the \ in front of the |
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:sunilbains
ID: 21754797
GNU sed version 4.0.7
I dont want  to substitute tab with "|"
sed 's/[ \t]*\|/|/g'  ---  this is what this comand doing???
for below record,
20080609|67961856|EQUITY PARTNERS 2004 EMPLOYEE FUND, L.P       |EQUITY PARTNERS 2004 EMPLOYEE FUND, L.P        |

output should be
20080609|67961856|EQUITY PARTNERS 2004 EMPLOYEE FUND, L.P  |EQUITY PARTNERS 2004 EMPLOYEE FUND, L.P |




0
 
LVL 84

Expert Comment

by:ozo
ID: 21754831
did you try it without the \ in front of the |
sed 's/[ \t]*|/|/g'  
0
 

Author Comment

by:sunilbains
ID: 21754953
Hi,
It worked..
But will it replace tab between two words with space  also?. or it will jon two words
for example EQUITY                 PARTNERS    will it be EQUITY PARTNERS  or EQUITYPARTNERS
0
 
LVL 1

Expert Comment

by:pepecura
ID: 21755075
sed 's/[\t*]//g'

should work. * character is inside the brackets.
0
 
LVL 84

Expert Comment

by:ozo
ID: 21755132
Do you want it to replace tab between two words with space  also?.
0
 

Author Comment

by:sunilbains
ID: 21755222
hi,
I tried this command sed 's/[\t*]//g'
it worked fine for everything. So this command basicallt replace all TAB with nothing??
So instead of sed 's/[ \t]*|/|/g'    i can rely on sed 's/[\t*]//g'  for deleting tabs from the file ?
0
 
LVL 84

Expert Comment

by:ozo
ID: 21755291
That will also delete any * character anywhere in the file?
the ^ or $ or | restricts it to only deleting next to the beginning of the line, end of the line or | character respectively
0
 

Author Comment

by:sunilbains
ID: 21755404
by saying substitute tab with space i ment that I dont want to join two words  after deleting tab between them
for example. EQUITY                 PARTNERS   should  be EQUITY PARTNERS  not  EQUITYPARTNERS
But i think command sed 's/[\t*]//g'  will not append two words. Correct me if iam wrong??
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 21755466
s/[\t ]\{1,\}/ /g
will replace strings of one or more tabs and spaces with space
0

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question