Awk Command with Word as Delimitor

Awk Command with Word as Delimitor

How to I use awk to cut based on a word that keeps everything after it : Example:

File.txt > 
XXXXWORDNNNNNN
XXXWORDNNNNNNN
XXWORDNNNNNNNN
XWORDNNNNNNNNN
WORDNNNNNNNNNN

output desired:

File.txt >
NNNNNN
NNNNNNN
NNNNNNNN
NNNNNNNNN
NNNNNNNNNN

1 Answer

cat File.txt | awk -F"WORD" '{ print $2 }'

The -F parameter usually searches for a single character as a delimiter, but since you wanted to use a string of letters as your delimiter, it must be put in double quotes.

The $2 means all the text following "WORD" ... unless "WORD" reoccurs in the line of text. If that happens then you'll only see the text in between the first and second occurrence of "WORD".

I hope this helps.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.