I have file(file.txt) contains the following
aa=testing
bb=hello
cc=hi
Expected result
the value of aa is testing
How to use grep to find the value of aa?
grep -oP 'aa=\K.*' file.txt
Output:
testing
See: http://www.charlestonsw.com/perl-regular-expression-k-trick/
awk -F= '/^aa=/ { print $2 }' file
sed -n '/^aa=/s|^.*=||p' file
sed -n 's|^aa=||p' file
Output:
testing
awk and you get awk -F= '/^aa/ && $0=$2'
grep aa= file.txt, but if you want the output to literally bethe value of aa is testing, you can't use grep.