15-03-2019
This commit is contained in:
77
docs/Linux/string.md
Normal file
77
docs/Linux/string.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# String
|
||||
|
||||
|
||||
|
||||
Supprimer la 1ere ligne d'un fichier:
|
||||
|
||||
```bash
|
||||
$ npm ls | sed '1,1d'
|
||||
```
|
||||
|
||||
Supprimer les 2 premières lignes d'un fichier:
|
||||
|
||||
```bash
|
||||
$ npm ls | sed '1,2d'
|
||||
```
|
||||
|
||||
|
||||
|
||||
Supprimer les lignes contenant un motif:
|
||||
|
||||
```bash
|
||||
$ npm ls | grep -v 'motif'
|
||||
```
|
||||
|
||||
|
||||
|
||||
Récupérer la 1ere sous-chaine d'une chaine:
|
||||
|
||||
```bash
|
||||
$ string='924782627 GPX Editor (2.96.10)'
|
||||
|
||||
$ echo "$string" | awk '{print $1}'
|
||||
924782627
|
||||
```
|
||||
|
||||
|
||||
|
||||
Récupérer tout sauf la 1ere sous-chaine d'une chaine:
|
||||
|
||||
```bash
|
||||
$ string='924782627 GPX Editor (2.96.10)'
|
||||
|
||||
$ echo "$string" | awk {'first = $1; $1=""; print $0'}
|
||||
GPX Editor (2.96.10)
|
||||
|
||||
# Supprimer le 1er espace
|
||||
$ echo "$string" | awk {'first = $1; $1=""; print $0'}| sed 's/^ //g'
|
||||
GPX Editor (2.96.10)
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
awk:
|
||||
|
||||
```bash
|
||||
$ string='924782627 GPX Editor (2.96.10)'
|
||||
|
||||
$ echo "$string"
|
||||
924782627 GPX Editor (2.96.10)
|
||||
# Par défaut le séparateur de awk est l'espace
|
||||
$ echo "$string" | awk '{print $1}'
|
||||
924782627
|
||||
$ echo "$string" | awk '{print $2}'
|
||||
GPX
|
||||
$ echo "$string" | awk '{print $4}'
|
||||
(2.96.10)
|
||||
# On met '(' comme séparateur
|
||||
$ echo "$string" | awk -F "(" '{print $1}'
|
||||
924782627 GPX Editor
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user