Sam
Sam

Reputation: 8202

How do I count number of columns in each line using vi?

I have a file which is supposed to have exactly 8 columns on each line. But apparently there are a few lines that have an extra 'tab'. Is it possible in vi to search for only those lines that contain column more than 8 so that the problem can be fixed?

Upvotes: 0

Views: 1279

Answers (2)

Conner
Conner

Reputation: 31070

To search for any line with more than 8 characters try /^.\{8}.\+$

Step by step

/ - start a search

^ - means "beginning of the line"

. - any character

\{8} - 8 of the preceding match (in this case... "any character")

. - any character

\+ - 1 or more of the preceding match

$ - end of the line

Upvotes: 1

Gilbert
Gilbert

Reputation: 3776

Try the following / search:

/^.........

(that's 9 periods)

Upvotes: 0

Related Questions