Shell Script to convert multilines to single lines

Hi,

I need to create an script which reads multi lines and convert it to single line or enter escape sequence at end "\".
e.g.

#!/bin/sh

echo -e "provide me query to run"
read query 

create table test(
id int(11),
name char);

echo $query

But it's failing because of multi line i need output as follows:

create table test(id int(11),name char);

For this i tried

read query '+'  \

but it fails. Is there any way to do it means read parse multi lines into single line ?

Thank you.

Not sure if this is what you want but you can try this:

awk '/create/{c=2}c-->0{printf $0;next}1' file
nawk '1' ORS="" infile.txt

input:-

create table test(
id int(11),
name char);

output:-

create table test(id int(11),name char);

:cool::cool::cool:

And how about the other lines of the script?
He only needs to convert the given three lines of that script to one line.

Dear Franklin52;
he said in his thread:-

I think there are no other lines than the ones that he will put using read function.

another question ...what if the the multi lines (begin with "create") contain more than 3 row? then your code will fail as well.

Regards

Try this:

awk '{print $0}' infile.txt | tr -d "\n"

You're right, but the OP didn't mention anything like that so I assume that there is only one SQL command in the script otherwise the OP should clarify his question.

Regards

modified code that will work for general cases:-

kindly notice that the line ended with ";" like PERL line codes.

nawk '{sub(/;/,";\n",$0)}1' ORS=""  file.txt

i/p

IDName  Column1 name    value
ID1     a1      ppp     10;

create table test(
id int(11),
name char);


ID1     a6      ppp     79;

o/p

IDName  Column1 name    valueID1        a1      ppp     10;
create table test(id int(11), name char);
ID1     a6      ppp     79;

:cool::cool::cool: right?

BR

I took the original poster's help request to mean that he wants a script that will take multiline input (from a user or standard input) and merge it into a single line which should be stored in the variable $query. I also assumed that the three-line sql fragment in the script was a poorly-placed sample of the input, as whether it's three lines or one, that code in a sh script will simply generate an error.

Proceeding under those assumptions, my proposed solution is:

#!/bin/sh

echo 'Enter your query (press Control-D when finished):'
query=$(tr -d \\n)
echo $query

Regards,
Alister