Solved

Linux: Using echo to copy file with whitespace removed

Posted on 2013-11-01
3
315 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
  • 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:

777 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