Replace exact word with blank

i have a file with the below content
file1.txt

ALERTADMIN.FIELD
ALERTADMIN.TX_ALERTS_LOG

i have another file
file2
ALERTADMIN.FIELD
ALERTADMIN.FIELD_WS
ALERTADMIN.SECTION_FIELD_WS
ALERTADMIN.TX_ACCT_PROCESSING_WORK_TABLE
ALERTADMIN.TX_ACCT_REVIEW_EXEC_METRICS
ALERTADMIN.TX_ALERTS_ERRORS
ALERTADMIN.TX_ALERTS_PROCESSING_QUEUE

Now for every line in file1, if it is present in file2 then it has to be replaced with the blank.

Here ALERTADMIN.FIELD is present is both file1 and file2. In file2 i want to replace it with blank

Please make sure that the word ALERTADMIN.FIELD_WS is not replaced with blank and _WS is left out

So my output has to be like this

ALERTADMIN.FIELD_WS
ALERTADMIN.SECTION_FIELD_WS
ALERTADMIN.TX_ACCT_PROCESSING_WORK_TABLE
ALERTADMIN.TX_ACCT_REVIEW_EXEC_METRICS
ALERTADMIN.TX_ALERTS_ERRORS
ALERTADMIN.TX_ALERTS_PROCESSING_QUEUE

awk 'NR==FNR{a[$0]++}!a[$0]' file1 file2

---------- Post updated at 06:29 AM ---------- Previous update was at 06:29 AM ----------

To keep the forums high quality for all users, please take the time to format your posts correctly.

  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags and by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote

thanks a lot.

it worked :slight_smile: