Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the common command perl in Linux

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use the Linux command perl, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Linux commonly used commands perl commands are perl language interpreters, which are responsible for interpreting and executing perl language program methods.

Command format usage: perl [options] [parameters] Common option-o specifies the delimiter of the input record in octal form (also saved in the special variable $/ in perl)-a starts the automatic split mode when used with-n or-p. This mode splits the input lines and places them in a special array called @ F-c to make perl check the syntax of the script, and then exit-C to enable perl to use the original wide-character API on the target system. -d run the script-e under the perl debugger using the command line,-F if-an is used, this parameter can be used to specify the split mode-h prints out a summary of all options-I indicates that the text processed by the structure-I causes perl to add line end processing for the module search directory-l, when used with the-n and-p switch, this switch automatically removes $/ from the input data And set $\ (output record delimiter) to octnum so that the print statement can use the delimiter. -m [-] module includes the specified module in the script before executing the script-n lets perl try the while () loop in the script-p asks perl to add the following loop to the script:-P before perl compiles Run your own script through C preset handlers-s allows switch parsing on the command line-S lets perl try PATH environment variables to search for scripts-T force open error checking-u causes perl to know that kernel-U allows perl to do unsafe operations after compiling the script Such as deleting the directory, etc.-v prints out the version of perl and the level of the package-V:name prints out a summary of specified configuration variables-w prints a warning message-W starts a warning message regardless of the status of no warnings or $^ W-x directory notifies the perl script to be embedded in the message, and the text will not be processed until the first line of code is #! Begins and contains the character "perl"-X disables warning messages regardless of the status of use warnings or $^ W-optional, indicating the end position of these switches used refer to the example parsing Perl program

[deng@localhost tmp] $perl test.sh hello world [deng@localhost tmp] $other uses

# perl-p-i.bak-e's /\ bfoo\ b perl *. C # replace foo in all C programs with bar, and backup the old files to .bak # perl-i.bak-pe's / (\ d +) / 1 + $1 / ge' file1 file2... # add a # perl-pie's /\ r\ n /\ nfile # to the value that appears in each file. Replace the newline character\ r\ nwith\ n # perl-pie's /\ n /\ nUniverse g'file # replace the newline character\ nwith\ r\ n # perl-lane 'print "@ F [0.. 4] $F [6]"' file # display fields 0-4 and 6 The field delimiter is a space # perl-F:-lane 'print "@ F [0.4]\ n" / etc/passwd # field separator is not a space but a colon # perl-ne' print if / ^ START$/.. / ^ END$/' file # shows the part between START and END # perl-ne 'print unless / ^ START$/.. / ^ END$/' file # does not display the section # perl-pe 'exit if $between START and END. > 50 'file # display the first 50 lines # perl-ne' print unless 1. 10 'file # does not display the first 10 lines # perl-ne' print if 15.. 17 'file # shows 15 to 17 lines # perl-lne' print substr ($_, 0,80) = "" 'file # take the first 80 characters per line # perl-lne' print substr ($_ 10) = "" 'file # discard the first 10 characters per line # perl-ne' print if / comment/' duptext # find the comment string # perl-ne 'print unless / comment/' duptext # find the line # perl-ne' print if / comment/ without the comment string | / apple/' duptext # find the line # perl-lane 'print $F [4] + $F [- 2]' # calculated field containing comment or apple Sum of 4 and penultimate fields # perl-e 'print sort' file # files by line # perl-00-e 'print sort' file # files by paragraph # perl-0777-e 'print sort' file1 file2 # multiple files by file content And return the merged file # perl-e 'print reverse' file1 # file inverted by line # perl-ne 'printf "% x\ n", $_' # 10 converted to hexadecimal # perl-ne 'printf "% o\ n" $_'# 10 to octal # perl-ne 'print hex ($_). "\ n"' # hexadecimal to decimal # perl-ne 'print oct ($_). "\ n"' # octal to decimal # perl-ne 'print eval ($_). "\ n"' # simple calculator above is all the contents of the article "how to use Linux commands perl" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report