user327685 user327685 - 5 months ago 7
Bash Question

Delete all strings containing x amount of something

I have a rather big text file containing strings that look like this:

//a/b/ww/d/
//b/d/we/c/
//a/b/as/d/e/
//af/y/x/f/e/
//b/d/we/c/


I am trying to remove all the lines that have only 6 forward slashes in them.

The text between the slashes is random and can be longer or shorter.

Desired output:

//a/b/as/d/e/
//af/y/x/f/e/


What would be the most efficient way to do this?

Answer

That is a tailor-made job for awk to act on count of NF (number of fields) deliited by /:

awk -F/ 'NF != 7' file

//a/b/as/d/e/
//af/y/x/f/e/

NF==7 means there are 6 slashes (delimiter) in a line.