help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] checking file line: 'commit;'


From: John McKown
Subject: Re: [Help-bash] checking file line: 'commit;'
Date: Thu, 11 Aug 2016 09:53:38 -0500

On Thu, Aug 11, 2016 at 9:34 AM, Paolo Supino <address@hidden>
wrote:

> Hi Chet
>
> thank you for the reply, I tried [ "$string" = 'commit;' ] but it didn't
> work :-( and I don't think that case cuts it for my problem.
>
> Maybe it's worth writing what I'm trying to achieve... I have a set of
> directories with a lot (10 of thousands) of SQL scripts that I need to
> verify that the last statement is 'commit;'...
>
> What I thought of doing was: If while reading a SQL script if it meets
> 'commit;' remember the line number it found it on (I use readarray/mapfile
> and for loop to parse the SQL scripts). Afterwards check if another index
> that gets incremented every time there's a SQL statement in the script. If
> the second index is bigger than 'commit;' line number point it out...
>
>
> If anyone has a better solution, I'm willing to read and learn...
>

​I'm not sure that this is "better", but it should work. What this does is
check that the last line of a given file has the string "commit;" possibly
followed by some blanks.

cat ${file} | tail -n 1 | egrep '(^|[[:space:];)commit​; *$' || echo "last
thing in ${file} does not end with a commit;"

In a little script, this might look like:

for file in *;do
    cat "${file}" | tail -n 1 | egrep '(^|[[:space:];])commit; *$' || echo
"Last data in ${file} does not in with a commit;"
done

The regular expression in the egrep command can be translated into English
something like: Find the string "commit;" in the line. It can be preceded
by the start of line, any "white space" character (blank, tab, etc), or a
semi-colon. It can be followed by zero or more space characters before the
end of the line. The "tail -n 1" just copies the last line of the file into
the egrep.



>
> TIA
> Paolo
>
>
-- 
Klein bottle for rent -- inquire within.

Maranatha! <><
John McKown


reply via email to

[Prev in Thread] Current Thread [Next in Thread]