Difference between revisions of "Tr"

From wikieduonline
Jump to navigation Jump to search
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{draft}}
 
 
{{lowercase}}
 
{{lowercase}}
[[wikipedia:tr]]
+
<code>[[wikipedia:tr (Unix)]]</code> translate characters
 +
* https://man7.org/linux/man-pages/man1/tr.1p.html
 +
 
  
  
 
[[Concatenate]] [[lines]] on a [[file]]:
 
[[Concatenate]] [[lines]] on a [[file]]:
[[cat]] file | tr '\n' ' '
+
* <code>[[cat]] file | tr '\n' ' '</code>
 +
* <code>[[cat]] file | [[xargs]]</code>
 +
 
 +
Remove [[newline]] [[character]]
 +
* <code>tr -d '\n'</code>
  
 
Concatenate/[[merge]] every 2 lines:
 
Concatenate/[[merge]] every 2 lines:
Line 13: Line 18:
 
  [[cat]] file | tr '\n' ''
 
  [[cat]] file | tr '\n' ''
 
  tr: when not truncating set1, string2 must be non-empty
 
  tr: when not truncating set1, string2 must be non-empty
 +
 +
 +
tr --help
 +
tr: illegal option -- -
 +
usage: tr [-Ccsu] string1 string2
 +
        tr [-Ccu] -d string1
 +
        tr [-Ccu] -s string1
 +
        tr [-Ccu] -ds string1 string2
  
 
== Related commands ==
 
== Related commands ==
 
* <code>[[awk]]</code>
 
* <code>[[awk]]</code>
 
* <code>[[paste]]</code>
 
* <code>[[paste]]</code>
 +
* <code>[[cut]], [[cut -d]]</code>
 +
* <code>[[column]]</code>
 +
* <code>[[tr -d]] '\r'</code>
  
 
== See also ==
 
== See also ==
 +
* {{tr}}
 
* {{cat}}
 
* {{cat}}
* {{files}}
 
 
  
 
[[Category:Linux]]
 
[[Category:Linux]]

Latest revision as of 09:11, 24 March 2023

wikipedia:tr (Unix) translate characters


Concatenate lines on a file:

Remove newline character

  • tr -d '\n'

Concatenate/merge every 2 lines:

cat /path/tofile.txt | paste -d " "  - -[1]


cat file | tr '\n' 
tr: when not truncating set1, string2 must be non-empty


tr --help
tr: illegal option -- -
usage: tr [-Ccsu] string1 string2
       tr [-Ccu] -d string1
       tr [-Ccu] -s string1
       tr [-Ccu] -ds string1 string2

Related commands[edit]

See also[edit]

  • https://stackoverflow.com/a/9605450
  • Advertising: