Split line of file from delimeter.

I have a below file.

INPUT FILE

select * from customer
MERGE INTO Archive; delete from Employee; using select * from customer; 
delete from employee; select * from Employee;
insert into employee(1,1);

OUTPUT FILE

select * from customer
MERGE INTO Archive
delete from Employee
using select * from customer
delete from employee
select * from Employee
insert into employee(1,1) 

I want to split the line from deimeter semicolun `;`
& each statement in single line.
It might be happen that Semicolon is not comming in line or not comming.

I try this with CUT command but it will work only on single line.

tr -s ';' '\n' < infile
sed 's/; *$//; s/; */\
/g' file

try also:

awk '$1=$1' RS=";|\n" input_file
1 Like

Another gawk/mawk (only gawk / mawk support a regex in RS instead of a single character) :

mawk NF RS="; *|\n" file

--
@rdrtx1: Using $1=$1 like that can be tricky if a $1 happens to be 0 (zero) or 0.0 for example..

This should be OK in all awk , but needed two awk :frowning:

awk '{gsub(/; */,"\n")}1' file | awk NF