Issue
I have a file with the following lines:
auth_service_oauth_secret_accfrsh
auth_service_oauth_secret_accfrshv12
auth_service_oauth_secret_accfrshv13
I would like to be able to remove only the first line, where my pattern will be only "accfrsh", but I tried with multiple sed commands and it's not working. All lines with the pattern "accfrsh" are removed or nothing change.
I tried the below sed commands (it doesn't matter with -e or -i) :
sed -e "/accfrsh/d" my_file (remove all lines)
sed -e 's/\<accfrsh\>//g' my_file (nothing changes)
sed -e "/'^'accfrsh'$'/d" my_file (nothing changes)
Solution
This might work for you (GNU sed):
sed '/_accfrsh\b/d' file
Delete lines which contain _accfrsh
followed by a word boundary.
Compare it to:
sed '/_accfrsh\B/d' file
N.B. The \b
is related to /<
and />
which denote the start and end of a word boundary (see here).
Answered By - potong Answer Checked By - Senaida (WPSolving Volunteer)