Home > Mobile >  parsing file using sed
parsing file using sed

Time:10-18

I have a file that has some data I want to get automatically using a script

the file looks like this

var1 = value1
var2   =  value2

I am trying using sed

sed -n -e 's/^.*var2\(.*\)/\1/p'

but I cannot manage to remove the spaces and the = sign

In general I do not know how many spaces there are

the expected result would be: value2

instead I get = value2

CodePudding user response:

I suppose this:

sed -n -e 's/^.*var2 [[:space:]]*=[[:space:]]*\(.*\)/\1/p' testfile.txt

works

CodePudding user response:

cat file | tr -d ' ' | cut -d'=' -f2
  • Related