Skip to content

Check balanced double quotes…

August 19, 2015

…or any other character!

Why? Usually I have the problem that writting shell scripts I miss some double (or single) quotes.

If script is short I can easily find where the error is but with long scripts that is not easy.

So I wrote following command to find rows with odd number of double quotes.

cat -n <script> | sed -e s/'[^”]’/”/g -e s/'””‘/”/g -e s/’$’/’X’/1 | cat -n | sed -e /'[[:digit:]][[:space:]]X$’/d

Output could be:

1242    “X

Saying that row 1242 has a problem with double quotes number.

It is possible to replace double quotes in [^”] and s/'””‘/”/g with any other character you want check if it is balanced.

From → Technology

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: