Shell script article 3

Source: Internet
Author: User
Tags character classes php explode
Shellscript article 3 01#xargscommand 0203#convert multiline input to single-line output 04catexample.txt | xargs0506#convert single-line input to multiline output 07catexample.txt | xargs-n30809 # custom split symbol similar to function PHPexplodeJS... shell script article 3 01 # xargs command 02 03 # convert multi-line input to single-line output 04cat example.txt | xargs 05 06 # convert single-line input to multi-line output 07cat example.txt | xargs-n 308 09 # custom delimiter similar to the function PHP explode JS split10echo "courier" | xargs-d X11 12 # use 13 echo "splitxsplitxsplitxsplitxsplitxsplitx" | xargs-d X-n 214 15 # simulate passing variable parameters to shell script 16 #! /Bin/bash17 # file ceche. sh18echo $ * '#'19 20 echo args.txt 21args122args223args324 25cat args.txt | xargs-n 2. /cecho. sh26args1 args227args3 args428 29 # xargs has an option-I can provide the above command execution sequence. we can use _ I to specify a replacement string, this string will be replaced during xargs extension. When-I and xargs are used in combination, each parameter will be executed once 30 31cat args.txt | xargs-I {}. /cecho. sh-p {}-l32 33 #-I {} specifies the replacement string. for each command parameter, the string {} is replaced by the parameter read from stdin, when-I is used, the command seems to be executed in a loop. if there are three parameters, the command will be executed three times, in each execution, {} is replaced with the corresponding parameter 34 35 # xargs and find are combined with 36 37 find. -type f-name "*. txt "-print | xargs rm-f 38 # This command is quite dangerous. we cannot predict whether the delimiters found by find are '\ n' or''. many file names contain space characters, xargs may mistakenly think of it as their delimiters. for example, hell text.txt will be considered as hell text.txt 39 40 # tr command 41 42 # it can be used to convert a set of strings into another set of strings, therefore, it is usually called the conversion command 43 44 echo "HELLO" | tr 'A-z'' A-Z' # Convert uppercase letters to lowercase 45 46 echo 12345 | tr '0-9 ''000000' # A simple encryption method. tr supports custom collection methods. 47 48 echo 9876543210 | tr '000000' 0-9' # decrypts 49 50 # deletes characters with tr 51 echo 'hello 123 "| tr-d '0-9' # Delete 0-9 numeric character 52 53 # Character set supplement 54 echo Hello 1 char 2 netxt 4 | tr-d-C' 0-9 \ n' # Delete all characters except 0-9 \ n 55 56 # compress character compressed consecutive white space characters 57 echo "GNU is not UNIX. recursive right? "| Tr-s ''58 59 # Add each row in the text to 60cat file.txt 61162263364cat file.txt | echo $ [$ (tr '\ n' + ') 0] 65 # We replace \ n with +, and the string is changed to 1 + 2 + 3 + 66 # The following 0 is supplemented to form an expression 67 $ [operation] # execution operator, therefore, we can obtain the following string 68 echo $[1 + 2 + 3 + 0] 69 70 # tr supported character classes 71 alnum: letters and numbers 72 alpha: Letters 73 cntrl: control characters, non-printable character 74 digit: Number 75 graph: graphical character 76 lower lowercase letter 77 print printable character 78 punct punctuation 79 space blank character 80 upper uppercase letter 81 xdigit hexadecimal character 82 83 # Use method 84 echo 'test' | tr [: lower:] [: upper:]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.