Split line of file from delimeter.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split line of file from delimeter.
# 1  
Old 09-18-2013
Split line of file from delimeter.

I have a below file.

INPUT FILE
Code:
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
Code:
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.

Last edited by Franklin52; 09-18-2013 at 07:16 AM.. Reason: Please use code tags
# 2  
Old 09-18-2013
Code:
tr -s ';' '\n' < infile

# 3  
Old 09-18-2013
Code:
sed 's/; *$//; s/; */\
/g' file


Last edited by MadeInGermany; 09-18-2013 at 06:11 AM..
# 4  
Old 09-18-2013
try also:
Code:
awk '$1=$1' RS=";|\n" input_file

This User Gave Thanks to rdrtx1 For This Post:
# 5  
Old 09-18-2013
Another gawk/mawk (only gawk / mawk support a regex in RS instead of a single character) :
Code:
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..

Last edited by Scrutinizer; 09-18-2013 at 05:57 PM..
# 6  
Old 09-19-2013
This should be OK in all awk, but needed two awk Smilie
Code:
awk '{gsub(/; */,"\n")}1' file | awk NF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split a txt file on the basis of line number

I have to split a file containing 100 lines to 5 files say from lines ,1-20 ,21-30 ,31-40 ,51-60 ,61-100 Here is i can do it for 2 file but how to handle it for more than 2 files awk 'NR < 21{ print >> "a"; next } {print >> "b" }' $input_file Please advidse. Thanks (4 Replies)
Discussion started by: abhaydas
4 Replies

2. Shell Programming and Scripting

Search for a pattern in a file and split the line into two lines

Hi All, Greetings everyone !!! I have a file which has many lines, out of which one line is as below. I need to search for pattern "varchar(30) Select" and if exists, then split the line as below. I am trying to achieve this in ksh. Can anyone help me on this. (8 Replies)
Discussion started by: Pradhikshan
8 Replies

3. Shell Programming and Scripting

How to split a file based on pattern line number?

Hi i have requirement like below M <form_name> sdasadasdMklkM D ...... D ..... M form_name> sdasadasdMklkM D ...... D ..... D ...... D ..... M form_name> sdasadasdMklkM D ...... M form_name> sdasadasdMklkM i want split file based on line number by finding... (10 Replies)
Discussion started by: bhaskar v
10 Replies

4. Shell Programming and Scripting

Split csv file by line count.

I have a very large csv file that I sort by the data that is in the second column. But what I need to do next is split the file in groups of say around 30,000 lines but don't split the data while there is still like data in the in the second column. Here is some of the data. ... (2 Replies)
Discussion started by: GroveTuckey
2 Replies

5. Shell Programming and Scripting

Split each column in TSV file to be new line?

My TSV looks like: Hello my name is John \t Hello world \t Have a good day! \t See you later! Is there a simple bash script that splits the tsv on tab to: Hello my name is John Hello world Have a good day! See you later! I'm really stuck, would appreciate any help! (5 Replies)
Discussion started by: pxalpine
5 Replies

6. Shell Programming and Scripting

Return all characters to the left of the last delimeter of each line

Hello, Working on a ksh script and a little stumped... how can I return all characters to the left of the last delimeter per line in a file, skipping any lines without that delimeter? ie, sample.txt: Once_upon-a-Midnight_dreary_while I pondered, weak_and weary over many a quaint and... (4 Replies)
Discussion started by: MoreCowbell
4 Replies

7. Web Development

split line based on delimeter SQL

I have a SQL query SELECT BLAH_ID, BLAH_CODE, DATEFORMAT(CALENDAR_DATE, 'MM-DD-YYYY') AS CALENDAR_DATE_STR, HOURS, 'N', FROM blah_tmp_tbl order by CALENDAR_DATE_STR,BLAH_ID,BLAH_CODE; OUTPUT TO 'MyExport.CSV' quote '' FORMAT ASCII; That gets me the below output; ... (2 Replies)
Discussion started by: ffdstanley
2 Replies

8. Shell Programming and Scripting

append delimeter count for each line in text file

Hi guys, plz tell me how to achieve this how to delete the lines in a file using sed command (6 Replies)
Discussion started by: hari908
6 Replies

9. Shell Programming and Scripting

Count the delimeter from a file and delete the row if delimeter count doesnt match.

I have a file containing about 5 million rows, in the file there are some records which has extra delimiter at random position. (we dont know the positions), now we have to Count the delimeter from each row and if the count of delimeter is not matching then I want to delete those rows from the... (5 Replies)
Discussion started by: Akumar1
5 Replies

10. Shell Programming and Scripting

Split File Based on Line Number Pattern

Hello all. Sorry, I know this question is similar to many others, but I just can seem to put together exactly what I need. My file is tab delimitted and contains approximately 1 million rows. I would like to send lines 1,4,& 7 to a file. Lines 2, 5, & 8 to a second file. Lines 3, 6, & 9 to... (11 Replies)
Discussion started by: shankster
11 Replies
Login or Register to Ask a Question