15-03-2019

This commit is contained in:
2019-03-15 20:20:37 +01:00
parent 53d2ce1c0d
commit 941984f1ee
52 changed files with 6416 additions and 70 deletions

77
docs/Linux/string.md Normal file
View 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
```