How to convert SQL comments using - to # using Perl?

UPDATE:

This is what works!

fgrep -ircl --include=*.sql -- -- *

I have different SQL files with "-" comments, and we migrated the latest version of MySQL, and she hates these comments. I want to replace - #.

I am looking for a recursive, one-line replacement replacer.

This is what I have:

perl -p -i -e 's/--/# /g'` ``fgrep -- -- *  

Example .sql file:

use myDB;

--did you get an error

I get the following error:

Unrecognized switch: --did (-h will show the actual parameters).

ps: fgrep, skipping the 2 dash, was just discussed here if you are interested.

Any help is appreciated.

+2
source share
3 answers

-e 's/.../.../' . fgrep -l , :

perl -p -i -e 's/--/# /g' `fgrep -l -- -- * `
+4

find inplace sed

find . -name '*.sql' -exec sed -i -e "s/^--/#/" '{}' \;

, --
, , :

INSERT INTO stuff VALUES (...) -- values used for xyz

-- ( , )

INSERT INTO stuff VALUES (42, "<!-- sboing -->") -- values used for xyz
+4

script:

#!/usr/bin/perl -i
use warnings;
use strict;

while(<>) {
    s/--/# /g;
    print;

}

--comment script, # comment. find, ls, grep .., ...

1 .

, ?

+1
source

Source: https://habr.com/ru/post/1743415/


All Articles