Skip to main content
added 8 characters in body
Source Link
glenn jackman
  • 88.5k
  • 16
  • 124
  • 179

For given input file input containing the following:

domain demesne 

To filter for lines containing domain:

$ awk '/domain/ { print }' input domain 

To filter for lines not containing domain:

$ awk '!/domain/ {print }' input demesne 

For filtering based on the field rather than the entire line, we can try the following for the new given input file:

example www.example.com exemplar www.example.net 

To filter out lines where the first field is contains example:

$ awk '$1 !~ /!example/ { print }' input exemplar www.example.net 

In your question, you used $0 which is the entire line rather than the first field.

For given input file input containing the following:

domain demesne 

To filter for lines containing domain:

$ awk '/domain/ { print }' input domain 

To filter for lines not containing domain:

$ awk '!/domain/ {print }' input demesne 

For filtering based on the field rather than the entire line, we can try the following for the new given input file:

example www.example.com exemplar www.example.net 

To filter out lines where the first field is example:

$ awk '$1 ~ /!example/ { print }' input exemplar www.example.net 

In your question, you used $0 which is the entire line rather than the first field.

For given input file input containing the following:

domain demesne 

To filter for lines containing domain:

$ awk '/domain/ { print }' input domain 

To filter for lines not containing domain:

$ awk '!/domain/ {print }' input demesne 

For filtering based on the field rather than the entire line, we can try the following for the new given input file:

example www.example.com exemplar www.example.net 

To filter out lines where the first field contains example:

$ awk '$1 !~ /example/ { print }' input exemplar www.example.net 

In your question, you used $0 which is the entire line rather than the first field.

added 410 characters in body
Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141

For given input file input containing the following:

domain demesne 

To filter for lines containing domain:

$ awk '/domain/ { print }' input domain 

To filter for lines not containing domain:

$ awk '!/domain/ {print }' input demesne 

For filtering based on the field rather than the entire line, we can try the following for the new given input file:

example www.example.com exemplar www.example.net 

To filter out lines where the first field is example:

$ awk '$1 ~ /!example/ { print }' input exemplar www.example.net 

In your question, you used $0 which is the entire line rather than the first field.

For given input file input containing the following:

domain demesne 

To filter for lines containing domain:

$ awk '/domain/ { print }' input domain 

To filter for lines not containing domain:

$ awk '!/domain/ {print }' input demesne 

For given input file input containing the following:

domain demesne 

To filter for lines containing domain:

$ awk '/domain/ { print }' input domain 

To filter for lines not containing domain:

$ awk '!/domain/ {print }' input demesne 

For filtering based on the field rather than the entire line, we can try the following for the new given input file:

example www.example.com exemplar www.example.net 

To filter out lines where the first field is example:

$ awk '$1 ~ /!example/ { print }' input exemplar www.example.net 

In your question, you used $0 which is the entire line rather than the first field.

Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141

For given input file input containing the following:

domain demesne 

To filter for lines containing domain:

$ awk '/domain/ { print }' input domain 

To filter for lines not containing domain:

$ awk '!/domain/ {print }' input demesne