Results 1 to 6 of 6
Hello Everyone,
I need your help again. I can't seem to figure out how to using either sed or awk to delete a space before and after a tab. I ...
- 04-03-2008 #1Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
Delete space before and after tab
Hello Everyone,
I need your help again. I can't seem to figure out how to using either sed or awk to delete a space before and after a tab. I have tried various lines that I could find and I either end up taking out all the spaces or all the tabs.
Here is the file right now. I used sed to find all the tabs and replace with the word TAB since I know the forums won't show it.
What I would like to see isCode:1 TAB ACCT11111111 TAB SERVER1\Backup of files on C$,System State and Services Database\admin01 TAB 22606 TAB 6551 2 TAB ACCT11111111 TAB SERVER1\Backup of Microsoft SQL Server\admin01 TAB 5138 TAB 229 3 TAB ACCT11111111 TAB SERVER2\Backup of files on C$,System State and Services Database\admin01 TAB 5990 TAB 1549 4 TAB ACCT11111111 TAB SERVER2\Backup of Microsoft SQL Server\admin01 TAB 19 TAB 1 5 TAB ACCT11111111 TAB SQL1\192.168.100.10\Backup of information_schema, lava, SQL1\admin01 TAB 15 TAB 1 6 TAB ACCT11111111 TAB UNIX-SSH\172.16.0.3\Backup of /\admin01 TAB 12948 TAB 987 7 TAB ACCT11111111 TAB UNIX-SSH\192.168.2.5\Backup of /\admin01 TAB 12 TAB 8 8 TAB ACCT11111111 TAB TECHIT1\Backup of files on C$, System State and Services Database\admin01 TAB 12772 TAB 3988 9 TAB ACCT11111111 TAB SERVER3\Backup of files on C$,System State and Services Database\admin01 TAB 5765 TAB 1399
Code:ACCT11111111TABSERVER1\Backup of files on C$,System State and Services Database\admin01 ACCT11111111TABSERVER1\Backup of Microsoft SQL Server\admin01 ACCT11111111TABSERVER2\Backup of files on C$,System State and Services Database\admin01 ACCT11111111TABSERVER2\Backup of Microsoft SQL Server\admin01 ACCT11111111TABSQL1\192.168.100.10\Backup of information_schema, lava, SQL1\admin01 ACCT11111111TABUNIX-SSH\172.16.0.3\Backup of /\admin01 ACCT11111111TABUNIX-SSH\192.168.2.5\Backup of /\admin01 ACCT11111111TABTECHIT1\Backup of files on C$, System State and Services Database\admin01 ACCT11111111TABSERVER3\Backup of files on C$,System State and Services Database\admin01
- 04-04-2008 #2Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
If we call "x" that data file, then something in the lines of the following, should work (in bash):
If you want, you can use sh instead of bash, but then the ${//} stuff will not work, and you are bound to use sed (which will be uglier, but more portable).#!/bin/bash
cat x | \
while read line
do
var=${line/[1234567890] /}
var=${var/ TAB /TAB}
echo ${var/TAB /TAB}
done
- 04-04-2008 #3Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
Thank you for the response. I was testing out the code and it is not reporting a TAB instead it changes it to a single whitespace. It also is removing out the \ characters. I do need those
.
- 04-04-2008 #4Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
- 04-04-2008 #5Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
That is still showing the space tab space when I run it. Basically I want the file to look like
ACCT11111111<TAB>SERVER1\Backup of files on C$,System State and Services Database\admin01<TAB>
I do not want a space after that last number before <TAB> and I do not want a space before the > in <TAB> on the first column. I do want the tab. I hope this helps.
- 04-04-2008 #6Linux User
- Join Date
- Jun 2007
- Posts
- 318
Try this using sed. \t signifies the TAB character in sed:
This will delete 1 or more spaces before and/or after a TAB.Code:sed 's/ *\t */\t/g' <file>


Reply With Quote
