Character replace in UNIX file

I have a .txt file in Solaris10 server that contans "\t" characters in a few lines. How can I get rid of those characters via any command line automated command.

Here is a sample line of the test file:
IKOTEST-11690 \tNeed an Album art icon for each video item \t for Letter "H"     15      51208      NULL

I need the output file(same name) that will have the above line replaced by:
IKOTEST-11690 \tNeed an Album art icon for each video item  for Letter "H"      15      51208      NULL

There are tabs in the file (multiple spaces) that I cannot lose.
Who is Participating?
Alex MatzingerConnect With a Mentor Database AdministratorCommented:
Oh, then yes, my command will remove every \t in the slightvw said, you can also use sed which would look like this(a new file will be created leaving the original intact):

sed 's/\\t//g' < yourfile > newFile

Open in new window

i prefer using vi or vim, but both will work.
slightwv (䄆 Netminder) Commented:
replacing ALL tabs is easy.

I believe this question is related to your other sql*loader question.

Are you sure you now want to replace ALL tabs?
Alex MatzingerDatabase AdministratorCommented:
open the file with vi and issue the following command:


Open in new window

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Alex MatzingerDatabase AdministratorCommented:
Sorry, ignore mine comment...that will erase all \t 's
slightwv (䄆 Netminder) Commented:
>>Sorry, ignore mine comment...that will erase all \t 's

That might be OK.  

The other question is here:

They are trying to load a text file with Oralce's sql loader utility.  This allows you to define field delimiters.  They set a TAB as a field delimiter but some of the text has a tab in it.

Instead of vi, I might go with sed so it can be more easily scripted.
toookiAuthor Commented:
Yes I am trying to remove all "\t" entries in the file...
toookiAuthor Commented:
Yes that seems to work. But is there any way to write single command like above to save in the source itself:
sed 's/\\t//g' < myfile > myfile
The above creates empty file.
Alex MatzingerDatabase AdministratorCommented:
if you have perl on your machine you can use this

perl -e "s/\\t//g" -pi $(find yourFile -type f)

That should do what you are looking for
Alex MatzingerDatabase AdministratorCommented:
made a minor error in that script it should be single quotes:

perl -e 's/\\t//g' -pi $(find yourFile -type f)

Open in new window

slightwv (䄆 Netminder) Commented:

Is this related to your sql loader question?
TomuniqueConnect With a Mentor Commented:
You get an empty file because you redirect to it

Command < Input  > Output

The shell prepares the environment to execute  the command, by setting up the file handles, environment variables etc, and THEN executing the program.
In this setup prep, the output is destroyed. (thus, the input is destroyed.)

Try this to "update in place" (not truly update in place, you will get a new inode)

Command < Input > TEMP && mv TEMP Input
&& says, execute the next command only if the previous command completed with a return code zero.
&& is a CYA, if Command fails, you save your original, (low on disk space, you don't end up with 1/2  a file -- generally better to not run the cmd, than trunk your file)

toookiAuthor Commented:
Thank you all.
amatzinger, I could not test the Perl command as I could not find any Perl installed on the server.
And slightwv, it is related to the same SQL Loader problem.
Tomunique' sed syntax worked for me. But the TEMP file I created does not seem to get deleted. That I could delete before the main script but It seems this delete of the TEMP file does not work:
# pwd
#ls -ltr TEMP
-rw-r--r--   1 root     root           8 Mar 12 15:49 TEMP
#cat myscript
D_DIR = /usr2/mydir
/bin/rm -rf "${D_DIR}/TEMP" >/dev/null 2>&1
#chmod 755 myscript
./myscript: D_DIR: not found

Why cannot the script find/delete the TEMP file?
don't put spaces around the equal sign...
it things D_DIR is a command

D_DIR=/usr2/mydir   all run together
toookiAuthor Commented:
Thank you Tomunique! That worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.