split data by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting split data by line
# 1  
Old 10-26-2011
split data by line

I would like break in two line by 'SNAG'

Current data:
Code:
SNAG|M1299063| | | | |0001.|0010.|AC64797|2008-02-18|093730.|YVR|AC64797|2008-02-18-09.37.30.250020|N|30|NO LEAKS OR CRACKS THIS A7 SCK  SNAG|M1299063| | | | |0001.|0014.|AC67109|2008-07-28|045404.|YVR|AC67109|2008-07-28-04.54.04.643650|N|41|NO LEAKS OR CRACKS FOUND ON THIS A-CHECK.SNAG|M1299063| | | | |0001.|0020.|AC63391|2009-06-28|054142.|YVR|AC63391|2009-06-28-05.41.42.501610|N|74|INSP. CARRIED OUT WITH NO LEAKS OR CRACKS NOTED THIS A16 CHECK.CFH 35,128.

I hope something like

Code:
SNAG|M1299063| | | | |0001.|0010.|AC64797|2008-02-18|093730.|YVR|AC64797|2008-02-18-09.37.30.250020|N|30|NO LEAKS OR CRACKS THIS A7 SCK  
SNAG|M1299063| | | | |0001.|0014.|AC67109|2008-07-28|045404.|YVR|AC67109|2008-07-28-04.54.04.643650|N|41|NO LEAKS OR CRACKS FOUND ON THIS A-CHECK.
SNAG|M1299063| | | | |0001.|0020.|AC63391|2009-06-28|054142.|YVR|AC63391|2009-06-28-05.41.42.501610|N|74|INSP. CARRIED OUT WITH NO LEAKS OR CRACKS NOTED THIS A16 CHECK.CFH 35,128.

Thanks so much
Javier

Last edited by radoulov; 10-26-2011 at 04:51 PM.. Reason: Code tags!
# 2  
Old 10-26-2011
Quick and straightforward, post back if you need more granularity:
Code:
~/unix.com$ echo 'SNAG|M1299063| | | | |0001.|0010.|AC64797|2008-02-18|093730.|YVR|AC64797|2008-02-18-09.37.30.250020|N|30|NO LEAKS OR CRACKS THIS A7 SCK  SNAG|M1299063| | | | |0001.|0014.|AC67109|2008-07-28|045404.|YVR|AC67109|2008-07-28-04.54.04.643650|N|41|NO LEAKS OR CRACKS FOUND ON THIS A-CHECK.SNAG|M1299063| | | | |0001.|0020.|AC63391|2009-06-28|054142.|YVR|AC63391|2009-06-28-05.41.42.501610|N|74|INSP. CARRIED OUT WITH NO LEAKS OR CRACKS NOTED THIS A16 CHECK.CFH 35,128.' | sed 's/SNAG/\nSNAG/g' | sed '/^$/d'

If data is a file:
Code:
~/unix.com$ sed 's/SNAG/\nSNAG/g' file | sed '/^$/d'


Last edited by tukuyomi; 10-26-2011 at 12:49 PM.. Reason: Added second code
# 3  
Old 10-26-2011
First all thanks so much.......

last question I have 4 key

- sed 's/SNAG/\nSNAG/g' file | sed '/^$/d'sed 's/SNAG/\nSNAG/g' file | sed '/^$/d'

- sed 's/SNAG/MARC/EA/ER/\nSNAG\nMARC\nEA\nER\/g' file | sed '/^$/d'sed 's/SNAG/\nSNAG/g' file | sed '/^$/d' ?? this way maybe working...?? sorry I'm new in unix

thanks again

Last edited by radoulov; 10-26-2011 at 04:51 PM.. Reason: Code tags!
# 4  
Old 10-26-2011
Can you post another sample data, please?
Try this:
Code:
~/unix.com$ sed 's/\(SNAG|\|MARC|\|EA|\|ER|\)/\n\1/g' file | sed '/^$/d'


Last edited by tukuyomi; 10-26-2011 at 04:55 PM.. Reason: Modified code for better matches
# 5  
Old 10-26-2011
full picture all the data

SNAG|C0802155| | | | |0001.|0001.|AC03896|1999-01-06|005050.|YYZ|AC03896|1999-01-06-00.50.50.649760|N|193|THERE IS ALSO STATI
C IN CABIN B AND D. CABIN A IS OK. SUSPECT MAIN MUX SINCE MANY CABINS ARE AFFECTED. DID NOT HAVE ENOUGH TIME TO INSTALL MUX.
(23-30-237). MUX WAS PLACED IN ONBOARD PARTS BOX. SNAG|C1325774| | | | |0001.|0001.|AC76728|2003-02-14|082132.|YYZ|AC76728|2
003-02-14-08.21.32.691870|N|29|REQ'S P/N 3200-11 NIL STK YYZ SNAG|C4671893| | | | |0001.|0001.|AC17721|2011-02-02|102358.|YY
C|AC17721|2011-02-02-10.23.58.037570|N|103|CHECKED ON THE ICMT TO SEE IF ALL THE FILES WERE PRESENT, THEY WERE. PLEASE COMMEN
T ON NEXT FLIGHT LEG. SNAG|C4815388| | | | |0001.|0001.|AC83966|2011-08-03|051810.|YYZ|AC83966|2011-08-03-05.18.10.490260|N|
72|P/N TR3-25ABS NOT FOUND ARTOS. SEE IPC 767-AWW 25-41-02-51D-001 ITEM#580 MARC|C4671893| | | | |0001.|0001.|AC17721|2011-02-02|102358.|YY
C|AC17721|2011-02-02-10.23.58.037570|N|103|CHECKED ON THE ICMT TO SEE IF ALL THE FILES WERE PRESENT, THEY WERE. PLEASE COMMEN
T ON NEXT FLIGHT LEG. SNAG|C4815388| | | | |0001.|0001.|AC83966|2011-08-03|051810.|YYZ|AC83966|2011-08-03-05.18.10.490260|N|
72|P/N TR3-25ABS NOT FOUND ARTOS. SEE IPC 767-AWW 25-41-02-51D-001 ITEM#580 EA|C4671893| | | | |0001.|0001.|AC17721|2011-02-02|102358.|YY
C|AC17721|2011-02-02-10.23.58.037570|N|103|CHECKED ON THE ICMT TO SEE IF ALL THE FILES WERE PRESENT, THEY WERE. PLEASE COMMEN
T ON NEXT FLIGHT LEG. ER|C4815388| | | | |0001.|0001.|AC83966|2011-08-03|051810.|YYZ|AC83966|2011-08-03-05.18.10.490260|N|
72|P/N TR3-25ABS NOT FOUND ARTOS. SEE IPC 767-AWW 25-41-02-51D-001 ITEM#580

thanks so much for you help (tukuyomi)
# 6  
Old 10-26-2011
See my previous post if you missed the edit, it should work with your sample data Smilie
# 7  
Old 10-27-2011
Code:
perl -pe 's/\s(SNAG|MARC|EA|ER)/\n$1/g' file.in > file.out


Last edited by Franklin52; 10-27-2011 at 05:39 AM.. Reason: Please use code tags, thank you
This User Gave Thanks to For This Post:
tip78
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split JSON to different data files

Hi Gurus, I have below JSON file, now I want to rewrite this file into a new file. I will appreciate if anyone can help me to provide the solution...I can't use jq. { "_id": "3ad893cb4cf1560add7b4caffd4b6126", "_rev": "1-1f0ce165e1d210319cf6e9f9c6ff654f", "name":... (4 Replies)
Discussion started by: manas_ranjan
4 Replies

2. Shell Programming and Scripting

Split a file into several files using a data

Hi All, I have file(File1) with data like below: 102100|LName|Gender|Company|Branch|Bday|Salary|Age 102100|bbbb|male|cccc|dddd|19900814|15000|20| 102101|asdg|male|gggg|ksgu|19911216||| 102102|bdbm|male|kkkk|acke|19931018||23| 102102|kfjg|male|kkkc|gkgg|19921213|14000|24|... (2 Replies)
Discussion started by: sarav.shan
2 Replies

3. Shell Programming and Scripting

Split File data using awk

HI Guys, I need to split the file in to number of files . file contains FILEHEADER and EOF . I have to split n number of times . I have to form the file with each splitted message between FILEHEADER and EOF using awk beign and end . how to implement please suggest. (2 Replies)
Discussion started by: manish8484
2 Replies

4. Shell Programming and Scripting

How to split a data assigned to a variable

The requirement is, there is a log file which contains a huge data. i need to get a particular field out of it by searching with another field. ex: 2011-03-28 13:00:07,423 : millis=231 q={ call get_data_account(?,?,?,?,?) }, params= i need to search for the word "get_data_account" in file... (1 Reply)
Discussion started by: Jassz
1 Replies

5. Shell Programming and Scripting

Split Date/time data to two

Hi all, I have logs(in a log file) with the following structure 20100916011501559;0.812;null;TRUE;;FALSE;0.812;0;0;;19 20100916011504762;0.015;null;TRUE;;FALSE;0;4|4;0.015;;4 20100916011504762;0;null;TRUE;;FALSE;0;0;0;;4 20100916011501731;3.343;null;TRUE;;FALSE;3.156;131|65;0.172;;11... (14 Replies)
Discussion started by: babai
14 Replies

6. Shell Programming and Scripting

split single line into two line or three lines

Dear All, I want to split single line into two line or three lines wherever “|” separated values comes using Input line test,DEMTEMPUT20100404010012,,,,,,,,|0070086|0070087, output shoule be test,DEMTEMPUT20100404010012,,,,,,,,0070086, test,DEMTEMPUT20100404010012,,,,,,,,0070087, (14 Replies)
Discussion started by: arvindng
14 Replies

7. Shell Programming and Scripting

Split a huge data into few different files?!

Input file data contents: >seq_1 MSNQSPPQSQRPGHSHSHSHSHAGLASSTSSHSNPSANASYNLNGPRTGGDQRYRASVDA >seq_2 AGAAGRGWGRDVTAAASPNPRNGGGRPASDLLSVGNAGGQASFASPETIDRWFEDLQHYE >seq_3 ATLEEMAAASLDANFKEELSAIEQWFRVLSEAERTAALYSLLQSSTQVQMRFFVTVLQQM ARADPITALLSPANPGQASMEAQMDAKLAAMGLKSPASPAVRQYARQSLSGDTYLSPHSA... (7 Replies)
Discussion started by: patrick87
7 Replies

8. Shell Programming and Scripting

Split a line on positions before reading complete line

Hi, I want to split before reading the complete line as the line is very big and its throwing out of memory. can you suggest. when i say #cat $inputFile | while read eachLine and use the eachLine to split its throwing out of memory as the line size is more than 10000000 characters. Can you... (1 Reply)
Discussion started by: vijaykrc
1 Replies

9. Shell Programming and Scripting

data break split

I am trying to figure out how to split a file when the data in the new line is different from the current line using a shell script? For eg.. if my input file contains the following 2341123 ABCAD 2341123 ANCAED 2341123 AVADV 3343434 ASDVAV 3343434 ASDFADF 4231232 ADACVAV 4231232... (3 Replies)
Discussion started by: gmatsoon
3 Replies

10. UNIX for Dummies Questions & Answers

Split data into multiple lines

All, I have a requirement where I will need to split a line into multiple lines. Ex: Input: 2ABCDEFGH2POIYUY2ASDGGF2QWERTY Output: 2ABCDEFGH 2POIYUY 2ASDGGF 2QWERTY The data is of no fixed lenght. Only the lines have to start with 2. How can this be done. (5 Replies)
Discussion started by: kingofprussia
5 Replies
Login or Register to Ask a Question