mirror of
https://github.com/trimstray/the-book-of-secret-knowledge
synced 2024-11-26 13:10:18 +00:00
add perl one-liners
- signed-off-by: trimstray <trimstray@gmail.com>
This commit is contained in:
parent
c039844fbf
commit
b2d6885850
1 changed files with 57 additions and 0 deletions
57
README.md
57
README.md
|
@ -1476,6 +1476,7 @@ In Firefox's addressbar, you can limit results by typing special characters befo
|
|||
* [awk](#tool-awk)
|
||||
* [sed](#tool-sed)
|
||||
* [grep](#tool-grep)
|
||||
* [perl](#tool-perl)
|
||||
|
||||
##### Tool: [terminal](https://en.wikipedia.org/wiki/Linux_console)
|
||||
|
||||
|
@ -3831,6 +3832,62 @@ grep -- -- filename
|
|||
grep "\-\-" filename
|
||||
```
|
||||
|
||||
##### Tool: [perl](https://www.perl.org/)
|
||||
|
||||
###### Search and replace (in place)
|
||||
|
||||
```bash
|
||||
perl -i -pe's/SEARCH/REPLACE/' filename
|
||||
```
|
||||
|
||||
###### Edit of `*.conf` files changing all foo to bar (and backup original)
|
||||
|
||||
```bash
|
||||
perl -p -i.orig -e 's/\bfoo\b/bar/g' *.conf
|
||||
```
|
||||
|
||||
###### Prints the first 20 lines from `*.conf` files
|
||||
|
||||
```bash
|
||||
perl -pe 'exit if $. > 20' *.conf
|
||||
```
|
||||
|
||||
###### Search lines 10 to 20
|
||||
|
||||
```bash
|
||||
perl -ne 'print if 10 .. 20' filename
|
||||
```
|
||||
|
||||
###### Delete first 10 lines (and backup original)
|
||||
|
||||
```bash
|
||||
perl -i.orig -ne 'print unless 1 .. 10' filename
|
||||
```
|
||||
|
||||
###### Delete all but lines between foo and bar (and backup original)
|
||||
|
||||
```bash
|
||||
perl -i.orig -ne 'print unless /^foo$/ .. /^bar$/' filename
|
||||
```
|
||||
|
||||
###### Reduce multiple blank lines to a single line
|
||||
|
||||
```bash
|
||||
perl -p -i -00pe0 filename
|
||||
```
|
||||
|
||||
###### Convert tabs to spaces (1t = 2sp)
|
||||
|
||||
```bash
|
||||
perl -p -i -e 's/\t/ /g' filename
|
||||
```
|
||||
|
||||
###### Read input from a file and report number of lines and characters
|
||||
|
||||
```bash
|
||||
perl -lne '$i++; $in += length($_); END { print "$i lines, $in characters"; }' filename
|
||||
```
|
||||
|
||||
#### Shell functions [<sup>[TOC]</sup>](#anger-table-of-contents)
|
||||
|
||||
##### Table of Contents
|
||||
|
|
Loading…
Reference in a new issue