Frage

Example I have ver.txt

#tac
version=xxx

I want to display only xxx.

I can try grep, sed, gawk.Just want to learn how to make it.

War es hilfreich?

Lösung 2

the awk answer:

awk -F = '$1=="version" {print $2}' file

Sed

sed -n '/^version=/s///p' file

If you are running these commands from a windows command prompt, then single quote is not a valid grouping character, you may have to do this

awk -F = "$1==\"version\" {print $2}" file

Andere Tipps

One of many ways is to use grep interpreting the pattern as a perl regular expression, and use a positive look-behind:

grep -oP '(?<=version=).*' infile
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top