Solved

Linux: Using echo to copy file with whitespace removed

Posted on 2013-11-01
3
321 Views
Last Modified: 2013-11-01
I use this to copy the text content of ''xyz.txt" to "ttt.txt":
echo $(< xyz.txt) > ttt.txt

Open in new window


How can I copy it with all whitespace removed?  All spaces, newlines and tabs should be REMOVED in the "ttt.txt" version.
0
Comment
Question by:hankknight
[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
  • 2
3 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 100 total points
ID: 39616478
All spaces, tabs and newlines? Really?

OK, so:

tr -d "[:space:]" < xyz.txt > ttt.txt
0
 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 400 total points
ID: 39616483
cat xyz.txt | tr -d " \t\n\r" > ttt.txt
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39616599
Why do you think MajorBigDeal's solution is so much better than mine?

Please don't confuse "[:space:]" and "[:blank:]". The latter matches just spaces (!), but the former matches space, tab, vertical tab, line feed (newline),  form feed and carriage return.
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

726 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