Note: I have included a screen shot of this task per the request of a commenter. This example in the jpeg deals with tabs and newlines.
Remove tabs
# more filename
esoft esoft esoft
esoft esoft esoft
# cat filename | tr -d space '\t'
esoftesoftesoft
esoftesoftesoft
# tr -d space '\t' < filename
Remove newlines
# cat filename | tr -d space '\n'
esoft esoft esoftesoft esoft esoft
Additional information:
Remove carriage returns
# cat filename | tr -d space '\r'
Remove spaces
# cat filename | tr -d space "space"
5 comments:
Remove CRs:
cat filename | xargs
Not exactly meant for removing CRs, but elegant and effective nevertheless.
Nice add-on tip ux-admin
How could you combine cat filename | xargs with another cat?
ie. cat file1 file2 > file3
where file1 would have it's CR's stripped?
The formatting of this post doesn't make the examples entirely clear to me. When I attempt the commands on a test file, I don't see the results (and, yes, I am replacing filename with the name of my file).
I think the issue is spacing between commands and results, et cetera. I'm sure it's all discernible by experienced experts, but it would more clear to everyone if it was more explicit in terms of This Command / This Result.
anonymous #2:
I have to agree with you and apologize for the inconvenience. I hope the jpeg makes it a bit clearer. I've added some additional explanations to the post, too.
Let me know what you think.
Post a Comment