splitting a huge line of file into multiple lines with fixed number of columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting splitting a huge line of file into multiple lines with fixed number of columns
# 1  
Old 09-11-2011
splitting a huge line of file into multiple lines with fixed number of columns

Hi,

I have a huge file with a single line.
But I want to break that line into lines of with each line having five columns.
My file is like this:
code:
"hi","there","how","are","you?","It","was","great","working","with","you.","hope","to","work","y ou."

I want it like this:
code:
"hi","there","how","are","you?"
"It","was","great","working","with"
"you.","hope","to","work","you"


I found the following link..but was not of much help.
https://www.unix.com/shell-programmin...ple-lines.html
It breaks the line the basis of number of characters in the lines.

In my case, the length of each column values is different.
My OS is AIX 5.3 with ksh

Anybody having an idea as how this cud be done?
Thanks
raj.
# 2  
Old 09-11-2011
Hi,

A solution using Perl:
Code:
$ cat infile
"hi","there","how","are","you?","It","was","great","working","with","you.","hope","to","work","y ou."
$ perl -ne 's/,/++$i % 5 ? "," : "\n"/ge; print' infile
"hi","there","how","are","you?"
"It","was","great","working","with"
"you.","hope","to","work","y ou."

Regards,
Birei
This User Gave Thanks to birei For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk issue splitting a fixed-width file containing line feed in data

Hi Forum. I have the following script that splits a large fixed-width file into smaller multiple fixed-width files based on input segment type. The main command in the script is: awk -v search_col_pos=$search_col_pos -v search_str_len=$search_str_len -v segment_type="$segment_type"... (8 Replies)
Discussion started by: pchang
8 Replies

2. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

3. Shell Programming and Scripting

Splitting XML file on basis of line number into multiple file

Hi All, I have more than half million lines of XML file , wanted to split in four files in a such a way that top 7 lines should be present in each file on top and bottom line of should be present in each file at bottom. from the 8th line actual record starts and each record contains 15 lines... (14 Replies)
Discussion started by: ajju
14 Replies

4. Shell Programming and Scripting

Splitting one line into multiple lines

Hi, I have one problem scenorio as below. my source file is : cat input_file. "hi","there","how","are","you?","It","was","great","working","with","you.","hope","to","work","y ou." my output should be like. "hi","there","how","are","you?", "It","was","great","working","with",... (7 Replies)
Discussion started by: abhilash_nakka
7 Replies

5. Shell Programming and Scripting

Removing duplicates in fixed width file which has multiple key columns

Hi All , I have a requirement where I need to remove duplicates from a fixed width file which has multiple key columns .Also , need to capture the duplicate records into another file . File has 8 columns. Key columns are col1 and col2. Col1 has the length of 8 col 2 has the length of 3. ... (5 Replies)
Discussion started by: saj
5 Replies

6. UNIX for Dummies Questions & Answers

Splitting up a text file into multiple files by columns

Hi, I have a space delimited text file with multiple columns 102 columns. I want to break it up into 100 files labelled 1.txt through 100.txt (n.txt). Each text file will contain the first two columns and in addition the nth column (that corresponds to n.txt). The third file will contain the... (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Shell Programming and Scripting

splitting huge xml into multiple files

hi all i have a some huge html files (500MB to 1GB). Each file has multiple <html></html> tags <html> ................. .................... .................... </html> <html> ................. .................... .................... </html> <html> .................... (5 Replies)
Discussion started by: uttamhoode
5 Replies

8. Shell Programming and Scripting

Splitting the line in multiple lines

Hi Guys, I need a help. I am pretty new to the shell level programing. I was trying to split a long lines to a multiple lines with few conditions. I goggle for the code and found some snippets and tried to modified it but I got few strange problems too. I have to split the lines if line is ... (3 Replies)
Discussion started by: dd_sh
3 Replies

9. Shell Programming and Scripting

Split a huge line into multiple 120 characters lines with sed?

Hello , I'm trying to split a file which contains a single very long line. My aim is to split this single line each 120 characters. I tried with the sed command : `cat ${MYPATH}/${FILE}|sed -e :a -e 's/^.\{1,120\}$/&\n/;ta' >{MYPATH}/${DEST}` but when I wc -l the destination file it is... (2 Replies)
Discussion started by: jerome_1664
2 Replies

10. Shell Programming and Scripting

Splitting a single line into multiple lines

I have a case where, I need to look into a file. Go to each line of the file, find the length of the line, if the length of the line is more than 75 chars, I need to split the line into multiple lines of 75chars max. If the length of the line is less than 75, we need not do anything. So at the... (4 Replies)
Discussion started by: thanuman
4 Replies
Login or Register to Ask a Question