How to: bash version (slow):
while read line ; do printf "%s" "$line " ; done < file
```

###### Delete string +N next lines

```bash
sed '/start/,+4d' /path/to/file
```

___

##### Tool: [grep](http://www.grymoire.com/Unix/Grep.html)

###### Search for a "pattern" inside all files in the current directory

```bash
grep -rn "pattern"
grep -RnisI "pattern" *
fgrep "pattern" * -R
```

###### Show only for multiple patterns

```bash
grep 'INFO*'\''WARN' filename
grep 'INFO\|WARN' filename
grep -e INFO -e WARN filename
grep -E '(INFO|WARN)' filename
egrep "INFO|WARN" filename
```

###### Except multiple patterns

```bash
grep -vE '(error|critical|warning)' filename
```

###### Show data from file without comments

```bash
grep -v ^[[:space:]]*# filename
```

###### Show data from file without comments and new lines

```bash
egrep -v '#|^$' filename
```

###### Show strings with a dash/hyphen

```bash
grep -e -- filename
grep -- -- filename
grep "\-\-" filename
```

###### Remove blank lines from a file and save output to new file

```bash
grep . filename > newfilename
```

##### 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 Tricks  [
[TOC]
](#anger-table-of-contents)

When you get a shell, it is generally not very clean, but after following these steps, you will have a fairly clean and comfortable shell to work with.

1) `script /dev/null -c bash`
2) Ctrl-Z (to send it to background)
3) `stty raw -echo; fg` (returns the shell to foreground)
4) `reset` (to reset terminal)
5) `xterm` (when asked for terminal type)
6) `export TERM=xterm; export SHELL=bash`

#### Shell functions  [
[TOC]
](#anger-table-of-contents)

##### Table of Contents

- [Domain resolve](#domain-resolve)
- [Get ASN](#get-asn)

###### Domain resolve

```bash