Reputation: 43
Suppose I have one text file(EmployeeDetails.txt
) in which the content is written(all name/value in new line) as mentioned below:-
EmployeeName=XYZ
EmployeeBand=D5
EmployeeDesignation=SSE
I need the Linux command which will read this file EmployeeDetails.txt
and give the value for EmployeeBand
. Output should be
D5
Upvotes: 0
Views: 433
Reputation: 18391
Using grep
: If anything is followed by EmployeeBand=
will be printed.
grep -oP 'EmployeeBand=\K.*' EmployeeDetails.txt
Using awk
where =
is used as field separator and second field is printed. if search criteria is meet.
awk -F'=' '/EmployeeBand/{print $2}' EmployeeDetails.txt
Using sed
,here the band D5
is captured is a group inside ()
and later used using \1
.
sed -r '/EmployeeBand/ s/.*=(.*$)/\1/g' EmployeeDetails.txt
Upvotes: 5