Solved

Linux: Using echo to copy file with whitespace removed

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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.:

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now