Personal tools

Difference between revisions of "Tr"

From MohidWiki

Jump to: navigation, search
m (1 revision)
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
  >for i in `find | grep Nomfich`; do j=`echo $i | tr [Nom] [nom]`; if [ $i != $j ]; then mv $i $j; fi; done;
 
  >for i in `find | grep Nomfich`; do j=`echo $i | tr [Nom] [nom]`; if [ $i != $j ]; then mv $i $j; fi; done;
 
This bash line transforms the ''Nomfich_*.dat'' files into ''nomfich_*.dat''
 
This bash line transforms the ''Nomfich_*.dat'' files into ''nomfich_*.dat''
 +
 +
> cat somefile.txt | tr -cd [:graph:]
 +
The above command deletes all non-printable characters (good for chomping a string...)
 +
 +
> tr -d "\r\n" file1
 +
The above command joins all lines from text input.
 +
 +
> tr -dc [:print:]
 +
The above command removes all non-printable characters (printable characters include white spaces).
 +
This means that it will effectively concatenate all lines coming from a text input.
 +
 +
==Related links==
 +
*[[sed]]
 +
*[[awk]]
 +
*[[regexp]]
 +
 
[[Category:Technology]]
 
[[Category:Technology]]
 
[[Category:Linux]]
 
[[Category:Linux]]
 
> cat somefile.txt | tr -cd [:graph:]
 
This line deletes all non-printable characters (good for chomping a string...)
 

Latest revision as of 15:16, 27 April 2010

Tr is a little linux utility which translates standard input and returns in standard output. It is useful for easily converting from uppercase to lowercase, etc...

Examples

>for i in `find | grep Nomfich`; do j=`echo $i | tr [Nom] [nom]`; if [ $i != $j ]; then mv $i $j; fi; done;

This bash line transforms the Nomfich_*.dat files into nomfich_*.dat

> cat somefile.txt | tr -cd [:graph:]

The above command deletes all non-printable characters (good for chomping a string...)

> tr -d "\r\n" file1

The above command joins all lines from text input.

> tr -dc [:print:]

The above command removes all non-printable characters (printable characters include white spaces). This means that it will effectively concatenate all lines coming from a text input.

Related links