Get the App
SLTechnology News&Howtos  ›  Network Security  › 

7.30 Pipeline tr Redirection exercise

Shulou Source: shulou.com Published: 2022-06-01 00:36:11 10月04日 Update

Exercise:

1. Convert the contents of the / etc/issue file to uppercase and save to the / tmp/issue.out file

Cat / etc/issue | tr'amurz 'Amurz' > / tmp/issue.out

2. Convert the information of the current system login user to uppercase and save it to / tmp/who.out file.

Who | tr 'AmurZ'aMurz' > / tmp/who.out

3. A linux user sends an email to root, requesting the title of the email is help, the body of the email is as follows, hello,I am user name, the system version is here please help me to check it thanks!

Echo-e'Hello, I am `whoami`, The system version is here, please help me to check it, thanks!\ nlsb_release | mail-s help root

4. Display the list of files under / root/ as a line, and separate the file names with spaces.

Method 1: ls / root | tr'\ n''

Method 2: echo $(ls-a) | tee > file1

5. The content of the file1 file is: 1 2 3 4 5 6 7 8 9 10 calculate the sum of all the numbers

Method 1:echo "1 2 3 4 5 6 7 8 9 10" | tr'+'| bc

Method 2:echo $[`echo "1 2 3 4 5 6 7 8 9 10" | tr'+'`]

6. Delete the ^ M character from the Winodows text file

Method 1:cat a.txt | tr-d'\ 015' > f2.txt

Method 2:cat a.txt | tr-d'\ r'> f2.txt

7. Process the string "xt,. | 1 jr#-smn2 c*/fe 3 uz 4", leaving only numbers and spaces in it.

Echo 'xt,. | 1 jr#-smn2 c*/fe 3 uz 4' | tr-cd [: digit:]'\ n'

8. Display the PATH variable on a separate line for each directory

Echo $PATH | tr':'\ n'

9. Delete the blank line of the specified file

Cat F1 | tr-s'\ n'

10. Display each word (letter) in the file on a separate line with no blank lines

Cat / etc/init.d/functions | tr-cs'[: alpha:]'\ n'

Replace all except letters with empty ones

Tags: File method line user message content uppercase letter character number space blank line independent between information word variable string sum file name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi MySQL Shulou Information Huawei