Skip to main content
added 779 characters in body
Source Link

Since you use fedora you have GNU sed and this should work:

s="  shipname       NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/;q0} ; s/^  ([[:lower:]]+)/\1 TEXT NULL,/'

This emulates a fake if.

if:

a NOT (/NOT/) is found inside the db structure then the first sed command is executed then, quit (q0) without executing the second statement.

else:

no NOT keyword is found, and the second instance is executed.


For the second reqirements :

sed "s/N'/'/g"

Globally search for N' and replace it with only '. I found useful to swap ' with " for sed command line delimiter and make it more clean without a lot of escaping.


Put the first sed inside a file:

#!/bin/sed -Ef

# If a NOT is found execute this:
# capture the column name and the value of this
/NOT/ {
    s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/

    # Quit without execute the other statement
    q0
}

# Else: If we are here then the database
# structure does not contains a length for the column;
# so it should be NULL
s/^  ([[:lower:]]+)/\1 TEXT NULL,/

The { command is used to group more sed command togheter.

The q is the quit command, it is used to make sed quit. Here i have use it to force sed exiting before encounter the last line if the first test succeded.

Since you use fedora you have GNU sed and this should work:

s="  shipname       NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/;q0} ; s/^  ([[:lower:]]+)/\1 TEXT NULL,/'

This emulates a fake if.

if:

a NOT (/NOT/) is found inside the db structure then the first sed command is executed then, quit (q0) without executing the second statement.

else:

no NOT keyword is found, and the second instance is executed.


For the second reqirements :

sed "s/N'/'/g"

Globally search for N' and replace it with only '. I found useful to swap ' with " for sed command line delimiter and make it more clean without a lot of escaping.

Since you use fedora you have GNU sed and this should work:

s="  shipname       NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/;q0} ; s/^  ([[:lower:]]+)/\1 TEXT NULL,/'

This emulates a fake if.

if:

a NOT (/NOT/) is found inside the db structure then the first sed command is executed then, quit (q0) without executing the second statement.

else:

no NOT keyword is found, and the second instance is executed.


For the second reqirements :

sed "s/N'/'/g"

Globally search for N' and replace it with only '. I found useful to swap ' with " for sed command line delimiter and make it more clean without a lot of escaping.


Put the first sed inside a file:

#!/bin/sed -Ef

# If a NOT is found execute this:
# capture the column name and the value of this
/NOT/ {
    s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/

    # Quit without execute the other statement
    q0
}

# Else: If we are here then the database
# structure does not contains a length for the column;
# so it should be NULL
s/^  ([[:lower:]]+)/\1 TEXT NULL,/

The { command is used to group more sed command togheter.

The q is the quit command, it is used to make sed quit. Here i have use it to force sed exiting before encounter the last line if the first test succeded.

added 2 characters in body
Source Link

Since you use fedora you have GNU sed and this should work:

s="shipnames="  shipname       NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/;q0} ; s/^  ([[:lower:]]+)/\1 TEXT NULL,/'

This emulates a fake if.

if:

a NOT (/NOT/) is found inside the db structure then the first sed command is executed then, quit (q0) without executing the second statement.

else:

no NOT keyword is found, and the second instance is executed.


For the second reqirements :

sed "s/N'/'/g"

Globally search for N' and replace it with only '. I found useful to swap ' with " for sed command line delimiter and make it more clean without a lot of escaping.

Since you use fedora you have GNU sed and this should work:

s="shipname       NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/;q0} ; s/^  ([[:lower:]]+)/\1 TEXT NULL,/'

This emulates a fake if.

if:

a NOT (/NOT/) is found inside the db structure then the first sed command is executed then, quit (q0) without executing the second statement.

else:

no NOT keyword is found, and the second instance is executed.


For the second reqirements :

sed "s/N'/'/g"

Globally search for N' and replace it with only '. I found useful to swap ' with " for sed command line delimiter and make it more clean without a lot of escaping.

Since you use fedora you have GNU sed and this should work:

s="  shipname       NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/;q0} ; s/^  ([[:lower:]]+)/\1 TEXT NULL,/'

This emulates a fake if.

if:

a NOT (/NOT/) is found inside the db structure then the first sed command is executed then, quit (q0) without executing the second statement.

else:

no NOT keyword is found, and the second instance is executed.


For the second reqirements :

sed "s/N'/'/g"

Globally search for N' and replace it with only '. I found useful to swap ' with " for sed command line delimiter and make it more clean without a lot of escaping.

added 440 characters in body
Source Link

Since you use fedora you have GNU sed and this should work:

s="shipname       NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/;q0} ; s/^  ([[:lower:]]+)/\1 TEXT NULL,/'

This emulates a fake if.

if:

a NOT (/NOT/) is found inside the db structure then the first sed command is executed then, quit (q0) without executing the second statement.

else:

no NOT keyword is found, and the second instance is executed.


For the second reqirements :

sed "s/N'/'/g"

Globally search for N' and replace it with only '. I found useful to swap ' with " for sed command line delimiter and make it more clean without a lot of escaping.

Since you use fedora you have GNU sed and this should work:

s="shipname       NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/;q0} ; s/^  ([[:lower:]]+)/\1 TEXT NULL,/'

For the second reqirements :

sed "s/N'/'/g"

Since you use fedora you have GNU sed and this should work:

s="shipname       NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^  ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) NOT NULL,$/\1 TEXT NOT NULL CHECK \(LENGTH\(\1\) <= \2\),/;q0} ; s/^  ([[:lower:]]+)/\1 TEXT NULL,/'

This emulates a fake if.

if:

a NOT (/NOT/) is found inside the db structure then the first sed command is executed then, quit (q0) without executing the second statement.

else:

no NOT keyword is found, and the second instance is executed.


For the second reqirements :

sed "s/N'/'/g"

Globally search for N' and replace it with only '. I found useful to swap ' with " for sed command line delimiter and make it more clean without a lot of escaping.

Source Link
Loading