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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.