LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-12-2016, 01:31 AM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 281

Rep: Reputation: Disabled
Removing all kinds of white space


I looked around and could not find satisfactory answers.
I sometimes copy strings from word editor like LibreWriter
into the console to run.

But now and then the command fails to run when I pasted it onto the console.

I know those command works because I have to retype it manually and run it.

So it must be due to hidden characters causing the command to fail, i.e. whitespaces, since librewrite is a word processor, not a text editor.

I looked at tr command, but it requires a file.
I like to run a command on a string and outputs a string without any white spaces. of any kind.

How do I do that?
Thanks.
 
Old 11-12-2016, 02:08 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,032
Blog Entries: 1

Rep: Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118
It would be difficult at best to try to guess what the differences are between what you type and what you copy/paste without any examples at all. Removing vaguely defined "any whitespace" may create a different set of problems resulting in the proverbial wild goose chase.

It would be more helpful if you could provide an actual example or two that fail, along with what you type to make each work.

And tr reads from stdin and writes to stdout, it does not require a file. That said, it is probably not what you need.
 
2 members found this post helpful.
Old 11-12-2016, 02:18 AM   #3
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 1,399
Blog Entries: 3

Rep: Reputation: 569Reputation: 569Reputation: 569Reputation: 569Reputation: 569Reputation: 569
Quote:
Originally Posted by fanoflq View Post
I like to run a command on a string and outputs a string without any white spaces. of any kind.
You could use "sed" for that, with character classes.

Code:
echo -e "a b c d \t e" | sed -e 's/[[:space:]]*//g'
I'm not sure how to fit that into copying and pasting though.
 
Old 11-12-2016, 02:21 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,057

Rep: Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916
You rarely want to eliminate all whitespace in a command string - better probably is
Code:
sed -e 's/[[:space:]]+/ /g'
 
1 members found this post helpful.
Old 11-12-2016, 02:50 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
I agree with all posted above:

1. No examples mean no way to assist

2. Would you really want to remove the white space between the command and its arguments, after all, that would be part of ALL white space

3. How would you think the intercept between your copy and the actual paste would work?

I feel maybe you need to rethink what you actually wish to do?
 
1 members found this post helpful.
Old 11-12-2016, 03:06 AM   #6
fanoflq
Member
 
Registered: Nov 2015
Posts: 281

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
It would be more helpful if you could provide an actual example or two that fail, along with what you type to make each work.

And tr reads from stdin and writes to stdout, it does not require a file. That said, it is probably not what you need.

And example would be doing a search for a file using find.
I would paste the file name from LibreWriter. Example.

find . -iname myFile.txt

Sometimes it was found.
But other times, I have to do the manual typing of the filename.
So it has to do with hidden characters from pasting.


Can you show an example of using tr to replace a string containing possibly some unknown white spaces of various types?
 
Old 11-12-2016, 06:25 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
You might want to think about what you are asking?

For any command where you are now pasting in text you will need something along the following format (using your example):
Code:
find . -iname "$(tr -d [[:space:][:cntrl:]]<<<"myFile.txt")"
So you would need all the parts in red EVERY time you wish to cut and paste something. You can probably tell that simply typing the text in would have been much quicker

I would suggest that if you copy and paste without highlighting multiple lines or past the edges of the text to be pasted you really shouldn't need to go through this scenario, at least I have never had to
when pasting from any type of file including those created under Windows.
 
1 members found this post helpful.
Old 11-12-2016, 09:53 AM   #8
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,658

Rep: Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987
if i understand correctly, i know this problem from html pages that like to use e.g. so-called "non-breaking space".
i just did
Code:
find -name '* *'
to find all filenames with normal space, followed by
Code:
find -name '* *' # that's a non-breaking space there between the asterisks
(the forum software insists on replacing the nb-space with an asterisk, so i inserted a normal space here. it works in my terminal, though)

to find all filenames with non-breaking space.
the first command gave results, the second none, because i don't have files with non-breaking space in their names.

i don't see any way to solve this in a way that op desires.
some characters simply are invisible, or look the same, yet they aren't.

edit:
some desktop environments or operating systems probably provide safetyguards against that sort of problem.
i.e., a file can never contain any "weird" characters.

Last edited by ondoho; 11-12-2016 at 10:02 AM.
 
Old 11-12-2016, 10:11 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,527

Rep: Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439
actually something is definitely wrong with the original post: whitespace is the default separator, so you do not need to replace them at all, and replacing whitespace will not solve any similar issues. There can be other hidden characters, but those are something else, not the whitespace chars.
by the way you may try to use roxterm, probably it can handle better such kind of drag&drop.
 
Old 11-12-2016, 10:40 AM   #10
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,658

Rep: Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987
funnt, somebody else just started this thread:
https://www.linuxquestions.org/quest...es-4175593315/
seems to fit the topic:
http://topics-of-interest.com/man1/detox
 
Old 11-12-2016, 12:12 PM   #11
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 7,685
Blog Entries: 10

Rep: Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080
How about a text editor instead of a word processor?
 
Old 11-13-2016, 01:46 AM   #12
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,032
Blog Entries: 1

Rep: Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118
Quote:
Originally Posted by fanoflq View Post
And example would be doing a search for a file using find.
I would paste the file name from LibreWriter. Example.

find . -iname myFile.txt

Sometimes it was found.
But other times, I have to do the manual typing of the filename.
So it has to do with hidden characters from pasting.


Can you show an example of using tr to replace a string containing possibly some unknown white spaces of various types?
What I am asking for is an actual copy/paste from LO to here, inside [code][/code] tags, of a real case, or two, which do not work for you. What I would like to see is the actual characters, commands and filenames, not a retyped example.

There are quite a few other non-ascii characters commonly used in word processors, besides white space. For example, quotes, asterisks, hyphens very well may be a problem but that is difficult to tell without an actual example.

You need to first identify the actual problem, whether it is whitespace or something else, and decide how to fix the text. Then you will need to decide how to pipe or wrap that into an executable command.

As I said, I do not think tr is the tool you need in any event, so will refrain from trying to answer that part of your question.
 
1 members found this post helpful.
Old 11-13-2016, 07:43 AM   #13
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,466

Rep: Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371
Perhaps the OP could investigate xclipboard?.
Here I have pasted a line containing an unbreakable space from LibreOffice Writer into xclipboard. For illustration I have saved to a file named clipboard, which I have then displayed using bpe.
Code:
File [1 of 1]: clipboard                                       Size: 0x00000022

COMMAND:                                              File position: 0x00000000

ADDRESS      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F   ASCII
-------------------------------------------------------------------------------
0x00000000   74 68 69 73 20 63 6F 6E 74 61 69 6E 73 20 61 6E   this contains an
0x00000010   20 75 6E 62 72 65 61 6B 61 62 6C 65 A0 73 70 61    unbreakable.spa
0x00000020   63 65                                             ce
Then I edited the line in xclipboard, deleting the unbreakable space then adding a normal space. Again, for illustration, I saved to a new file named clipboard1, which I have then displayed using bpe.
Code:
File [1 of 1]: clipboard1                                      Size: 0x00000022

COMMAND:                                              File position: 0x00000000

ADDRESS      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F   ASCII
-------------------------------------------------------------------------------
0x00000000   74 68 69 73 20 63 6F 6E 74 61 69 6E 73 20 61 6E   this contains an
0x00000010   20 75 6E 62 72 65 61 6B 61 62 6C 65 20 73 70 61    unbreakable spa
0x00000020   63 65                                             ce
The unbreakable space has been changed to a normal space. The edited selection is now available on the clipboard.
 
Old 11-13-2016, 08:43 AM   #14
fanoflq
Member
 
Registered: Nov 2015
Posts: 281

Original Poster
Rep: Reputation: Disabled
@allend:

Thanks.
May be a better idea is to map all visible characters back to itself,
and leave those invisible characters out.

That would automatically remove the unbreakable space in your example
without manual editing!

Is there a command to do that?

Last edited by fanoflq; 11-13-2016 at 08:44 AM.
 
Old 11-13-2016, 10:24 AM   #15
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
So is your plan to ignore all other posts and just cherry pick the ones you wish to answer? Interesting also that you have tried to tell someone else what would be better when you are the one asking the question in the first place??
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to removing white noise from a wav file? MikeyCarter Linux - Software 2 10-22-2009 11:54 AM
Help with script removing white space from a file tebucky Linux - Newbie 2 07-23-2009 12:04 PM
removing white spaces in the file tucs_123 Linux - Newbie 9 01-03-2009 11:28 AM
problems in removing white spaces from string of text monil Programming 7 03-08-2005 12:28 PM
removing white space accent11 Linux - Software 4 10-06-2004 02:30 AM


All times are GMT -5. The time now is 07:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration