Directive Daquan – Linux Directive: String Processing – RR

Directive Daquan – Linux Directive: String Processing – RR

Name: TR

### 1. Compare to the side to change all uppercase files in the directory to lowercase files?

There seems to be many ways, “TR” is one of them:

#! / bin / sh

DIR = “/ tmp / testdir”;

Files = `Find $ DIR -TYPE F`;

For i in $ files

DO

Dir_name = `Dirname $ I`;

Ori_filename = `basename $ I`

NEW_FILENAME = `Echo $ Ori_FileName | TR [: Upper:] [: Lower:]`> / dev / null;

#echo $ new_filename;

MV $ DIR_NAME / $ Ori_FileName $ DIR_NAME / $ NEW_FILENAME

DONE

### 2. ourselves … Lowercase to Uppercase

Tr Abcdef … [del] Abcde … [DEL]

TR A-Z A-Z

Tr ‘[: Lower:]’ ‘[: Upper:]’

Shell >> Echo “this is a test” | TR A-Z A-Z> WWW

Shell >> Cat WWW

This is a test

### 3. Remove the string of unwanted

Shell >> Tr -d this ### removes T.E.S.T

THIS

MAN

MAN

Test

e

### 4. Replace strings

Shell >> Tr -s “this” “test”

THIS

Test

TH

TE

Related Posts