sed 's/\(varchar[(]30[)]\) \(Select\)/\1\
\2/' Input_file
producing the output:
declare @newname varchar(30)
Select @newname = filename from table_bck
declare @newname varchar(30)
Select @newname = filename from table_bck
declare @newname varchar(30)
Select @newname = filename from table_bck
I believe GNU sed would allow \n instead of the \<newline> shown here, but it probably would also have to be told to conform to the standards with something like:
sed --posix 's/\(varchar[(]30[)]\) \(Select\)/\1\
\2/' Input_file
to get the parenthesized expressions to work correctly. (I don't have a GNU sed available to test at the current time.)
cat split | sed '/\(.*varchar.*[)] \)\(.*$\)/ {s//\1\n\2/}'
and:
sed 's/\(varchar[(]30[)]\) \(Select\)/\1\
\2/' Split
are:
the 1st form reads the data in split twice and writes the data in split twice while the 2nd form reads and writes the data once,
the 1st form uses two processes while the 2nd form uses one process,
the 1st form will transform any line containing the string varchar followed by zero of more arbitrary characters followed by a ) and a <space> while the 2nd form changes the <space> character in the string varchar(30) Select to a <newline> character (as specified in the 1st post in this thread),
the 1st form uses more system resources than the 2nd form,
the 1st form runs slower than the 2nd form, and
the 1st form will work on some systems that change a \n in a sed substitute command replacement string to a <newline> character and on systems with a standards conforming version of sed will print varchar(30)nSelect (note the n instead of the requested <newline>) while the 2nd form should do what you want with any sed .
Also, compare the results you get from the two above scripts with the input:
declare @newname varchar(30) Select @newname = filename from (table_bc)
I assume that your input file won't have anything that has more than one closing parenthesis on a line containing the string varchar , but the 1st form will give you something you don't want if that should ever occur. The 2nd form only transforms the text you said you wanted to transform.