error while extracting a line from a file based on identifier

here is the content of input file

CREATE TABLE `bla bla bla` (
  `allianceSiteId` int(11) DEFAULT NULL,
  `trunkGroupsId` int(11) DEFAULT NULL,
  `lastModified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY `allianceSiteId` (`allianceSiteId`,`trunkGroupsId`)
)

here is the part of the code whihc is inside a while loop reading a file

echo "whole line is : $line1"
 if  [[ `expr match "$line1" ".*CREATE TABLE.*"` != "0" ]]
 then
                firstword="$line1"
                fi
                echo "firstword : $firstword"
                lastword=") ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
                echo "lastword : $lastword"

here is the part of output

firstword : CREATE TABLE `AllianceSiteTrunkGroupTrunkGroupsMap` (
lastword : ) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
whole line is : )
expr: syntax error
firstword : )
lastword : ) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

my doubt is why am i getting "expr: syntax error"... if the $line1 has ) it should not go inside if statement... what is the solution...

good to use

if grep -q <search text> <<<"$line"

1 Like

what is the exact syntax...
if grep -q <CREATE TABLE> <<<"$line" .? is this correct... cause i am getting syntax error... does it need to be in double quotes.. the error is like this

./damp: line 112: syntax error near unexpected token `<<<'
./damp: line 112: `if grep -q <"CREATE TABLE"> <<<"$line"'

if grep -q "CREATE TABLE" <<<"$line"
then
...
fi.

1 Like

thanks it worked... :slight_smile: