1

I have a line looks like this:

some.com    *.some.com

The space is seemingly a tab space because when I move the keyboard arrow, one move will move me to the end of it (it does not seem multiple spaces because multiple spaces will need me to move the keyboard arrow multiple times).

This space is causing me problems. I need to:

  1. find what it is?

  2. replace it with a single space.

How to do this? I have tried removing multiple spaces but this seems a single character that could not be removed.

EDIT:

Just additional info. the program that uses this line complains: Invalid control character

  • 1
    There is actually no indication that this tab character is the "invalid control character" that your program is complaining about. How do you know it is? – Kusalananda May 15 at 7:38
1

It's a tab character.

tr -s '[:blank:]' ' ' <file >newfile

This would use tr to replace any tab or space in the file with a single space. Multiple spaces in the output would be squeezed into single spaces. The result in written to newfile.

To just replace single tabs with single spaces, use

tr '\t' ' ' <file >newfile
0

show-special-characters-in-unix-while-using-less-command

To see what that character is:

less -r sourcefile

or

od -c sourceFile

for a more verbose view.

unix-linux-sed-ascii-control-codes-nonprintable

To sed out the offending control code:

sed 's/'`echo "\033"`'/ /g'

where \033 is replaced with whatever is actually there.

0

you can eventually use this way too

sed -E "s,[[:space:]]+, ,g" /tmp/test

this will replace any single or multiple "white space" (space, tab) whith a single "space"

$ cat /tmp/test 
sdfsdfsdf    sdfsdfsdfsd
sdflksjdf    sdfélsdkfésldkf    ss

result

$ sed -E "s,[[:space:]]+, ,g" /tmp/test 
sdfsdfsdf sdfsdfsdfsd
sdflksjdf sdfélsdkfésldkf ss
  • [[:blank:]] matches a space or a tab only, [[:space:]] matches a few more characters (newline, carriage-return, form-feed, vertical tab). – Kusalananda May 15 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.