WebViewed 7k times 3 I need to edit a file in place within a perl script, so the oft used one liner: perl -p -e s///ig will not work for this situation. How do I get the same results from within a perl script? open (CRONTAB, "+) { if ($_ =~ /value/) { s/^\#+//; print "$_\n"; } } Web我已使用自動索引模塊配置 Nginx 以啟用目錄列表。 但我想擴展此功能以啟用文件編輯並保存它。 問題是我有一些需要監控的私有 IP,我已將這些 IP 添加到一個文件中,並制作了一個腳本以從文件中獲取 IP 並通過 Pinging 監控它們。 由於有時這些 IP 會因 DHCP 而更改,因此 …
Introduction to Perl one-liners - catonmat.net
WebDec 30, 2016 · A few Perl ways: perl -ne '/^HERE IT IS/ print' file > newfile perl -ne 'print if !/^HERE IT IS/' file > newfile perl -ne 'print unless /^HERE IT IS/' file > newfile You can add the -i switch to any of the examples to edit the file in place: perl -i.bak -ne '/^HERE IT IS/ print' file (g)awk awk '!/^HERE IT IS/' file > newfile WebFeb 16, 2024 · Remove certain lines from a file. find . -name "*.html" xargs perl -i -n -e 'print if $_ !~ m {ie8}'. -i means in-place editing. That is, open the file and whatever the perl command prints write back into the same file we have on the command line. -n go over the lines of the file (s) on the command line in a while loop and on each iteration ... health care fsa uses
How to search and replace a multi-line string in a file on Linux
WebMay 22, 2024 · 18. You can use a vi script: $ vi test.txt -c '%s/aaa/NNN/ wq' $ cat test.txt NNN NNN bbb ccc ddd. You're simply automating what would normally be entered when using vi in command mode (accessed using Esc: usually): % - carry out the following command on every line: s/aaa/NNN/ - subtitute aaa with NNN. WebSolution. Use the -iand -pswitches to Perl. Write your program on the command line: % perl -i.orig -p -e 'FILTER COMMAND' file1 file2 file3 ... Or use the switches in programs: … WebJan 23, 2024 · If you have several input files, each file with be individually in-place edited. But you can turn in-place editing off for a file (or a set of files) by using inplace=0 on the command line before that file: awk -i inplace -f script.awk file1 file2 inplace=0 file3 inplace=1 file4 In the above command, file3 would not be edited in place. golf t times in phoenix