1

I am working in linux and have a config file with a lot of single lines formatted like this:

Variable1=Value1
Variable2=Value2
Variable3=Value3

I need something I can run on command line that will echo the value for the respective variable. I have been playing with sed all day, but having a heck of a time. I'm not sure if that's even the best way. Any help would be super.

SQlBeginner
  • 65
  • 3
  • 9

2 Answers2

2
$ cat a.sh
Variable1=Value1
Variable2=Value2
Variable3=Value3 

$ source a.sh
$ echo "$Variable1"
Value1

Note, source will overwrite the value of Variable1 for the current shell.

iamauser
  • 11,119
  • 5
  • 34
  • 52
1

Search for the variable name and the equal sign, remove them, and print the result.

$ sed -n '/^Variable1=/{s/^Variable1=//;p}' config.txt
Value1
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358