• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

Linux: Using echo to copy file with whitespace removed

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
hankknight
Asked:
hankknight
  • 2
2 Solutions
 
woolmilkporcCommented:
All spaces, tabs and newlines? Really?

OK, so:

tr -d "[:space:]" < xyz.txt > ttt.txt
0
 
MajorBigDealCommented:
cat xyz.txt | tr -d " \t\n\r" > ttt.txt
0
 
woolmilkporcCommented:
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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now