mirror of
https://github.com/onceupon/Bash-Oneliner.git
synced 2024-11-26 06:17:01 +00:00
add sed and other
This commit is contained in:
parent
16db453a5f
commit
d90bb95c49
20
README.md
20
README.md
@ -285,7 +285,6 @@ grep -d skip 'bbo' /path/to/files/*
|
|||||||
|
|
||||||
## Sed
|
## Sed
|
||||||
[[back to top](#handy-bash-oneliner-commands)]
|
[[back to top](#handy-bash-oneliner-commands)]
|
||||||
|
|
||||||
##### Remove the 1st line
|
##### Remove the 1st line
|
||||||
```bash
|
```bash
|
||||||
sed 1d filename
|
sed 1d filename
|
||||||
@ -316,13 +315,20 @@ sed -E '/^.{5}[^2]/d'
|
|||||||
sed -i "/bbo/d" filename
|
sed -i "/bbo/d" filename
|
||||||
```
|
```
|
||||||
##### When using variable (e.g. $i), use double quotes " "
|
##### When using variable (e.g. $i), use double quotes " "
|
||||||
e.g. add >$i to the first line (to make a FASTA file)
|
e.g. add >$i to the first line (to make a bioinformatics FASTA file)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sed "1i >$i"
|
sed "1i >$i"
|
||||||
# notice the double quotes! in other examples, you can use a single quote, but here, no way!
|
# notice the double quotes! in other examples, you can use a single quote, but here, no way!
|
||||||
# '1i' means insert to first line
|
# '1i' means insert to first line
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### Using environment variable and end-of-line pattern at the same time.
|
||||||
|
```bash
|
||||||
|
# Use backslash for end-of-line $ pattern, and double quotes for expressing the variable
|
||||||
|
sed -e "\$s/\$/\n+--$3-----+/"
|
||||||
|
```
|
||||||
|
|
||||||
##### Delete/remove empty lines
|
##### Delete/remove empty lines
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -349,6 +355,11 @@ sed -i '$ s/.$//' filename
|
|||||||
sed -i '1s/^/[/' file
|
sed -i '1s/^/[/' file
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### Add string at certain line number (e.g. add 'something' to line 1 and line 3)
|
||||||
|
```bash
|
||||||
|
sed -e '1isomething -e '3isomething'
|
||||||
|
```
|
||||||
|
|
||||||
##### Add string to end of file (e.g. "]")
|
##### Add string to end of file (e.g. "]")
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -2044,6 +2055,11 @@ hostnamectl set-hostname "mynode"
|
|||||||
|
|
||||||
## Others
|
## Others
|
||||||
[[back to top](#handy-bash-oneliner-commands)]
|
[[back to top](#handy-bash-oneliner-commands)]
|
||||||
|
##### Copy a file to multiple files (e.g copy fileA to file(B-D))
|
||||||
|
```bash
|
||||||
|
tee <fileA fileB fileC fileD >/dev/null
|
||||||
|
```
|
||||||
|
|
||||||
##### Remove newline / nextline
|
##### Remove newline / nextline
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
Loading…
Reference in New Issue
Block a user