Domanda

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.

È stato utile?

Soluzione 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

Altri suggerimenti

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top