Home > Mobile >  Get specific text from file in bash
Get specific text from file in bash

Time:11-27

i have problem to show specific text. Example i will get only version number from text in file version.txt this: Version = "0.11.0"

can someone help me?

thanks

CodePudding user response:

You want just the numbers?

Perhaps

awk -F\" '/Version/ {print $2}' version.txt

CodePudding user response:

You can simply use cut:

cat version.txt | cut -d '=' -f2 | xargs

Or awk as others suggested:

cat version.txt | awk '{print $3}'

Both output: 0.11.0

The logic is based on the file format being consistent rather than focusing on the number extraction.
cut : prints the value after = | xargs : trims spaces
awk : prints the value on third place

These allow for example both x.x.x and x.x.x-RELEASE

  •  Tags:  
  • bash
  • Related