read one line file and separate into multiple lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read one line file and separate into multiple lines
# 1  
Old 12-02-2011
read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field.

example input line:
Code:
192.168.1.145;44535;software20.org;80;yes;ThuDec113;50;50.8384422011;ThuDec113;50;57.2764792011;0;00;06.438037;58;29;29;28;29;1;25;526;36045;0;0;0;0;1/1;1/1;0;0;0;0;82;5599;346.4;1.6;192.168.1.145;44536;software20.org;80;yes;ThuDec113;50;51.5587192011;ThuDec113;51;10.7557082011;0;00;19.196988;224;97;127;96;127;7;124;3963;173749;3;0;3;0;1/4;1/1;0;0;0;0;206;9051;351.8;2.4;192.168.1.145;44537;software20.org;80;yes;ThuDec113;50;51.8373732011;ThuDec113;51;11.4517212011;0;00;19.614348;455;185;270;184;270;5;267;2772;383480;3;0;3;0;1/4;1/1;0;0;0;0;141;19551;346.2;2.9;

desired output:
Code:
192.168.1.145;44535;software20.org;80;yes;ThuDec113;50;50.8384422011;ThuDec113;50;57.2764792011;0;00;06.438037;58;29;29;28;29;1;25;526;36045;0;0;0;0;1/1;1/1;0;0;0;0;82;5599;346.4;1.6;
192.168.1.145;44536;software20.org;80;yes;ThuDec113;50;51.5587192011;ThuDec113;51;10.7557082011;0;00;19.196988;224;97;127;96;127;7;124;3963;173749;3;0;3;0;1/4;1/1;0;0;0;0;206;9051;351.8;2.4;
192.168.1.145;44537;software20.org;80;yes;ThuDec113;50;51.8373732011;ThuDec113;51;11.4517212011;0;00;19.614348;455;185;270;184;270;5;267;2772;383480;3;0;3;0;1/4;1/1;0;0;0;0;141;19551;346.2;2.9;

thanks for your pointer...
# 2  
Old 12-03-2011
In your example the line is split after each 37th field...
Code:
awk -F";" -vOFS=";" '{for (i=37;i<=NF;i+=37) $i=$i"\n";gsub("\n;","\n")}1' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

2. Programming

Read text from file and print each character in separate line

performing this code to read from file and print each character in separate line works well with ASCII encoded text void preprocess_file (FILE *fp) { int cc; for (;;) { cc = getc (fp); if (cc == EOF) break; printf ("%c\n", cc); } } int main(int... (1 Reply)
Discussion started by: khaled79
1 Replies

3. Shell Programming and Scripting

Read each line and saving the line in separate files

Hi Experts, I am having a requirement like this; Input file EIM_ACCT.ifb|1001|1005 EIM_ADDR.ifb|1002|1004 EIM_ABD.ifb|1009|1007 I want to read each line of this file and pass each line,one at a time,as an argument to another script. eg; 1.read first line->store it to a file->call... (2 Replies)
Discussion started by: ashishpanchal85
2 Replies

4. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

5. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (2 Replies)
Discussion started by: erlanq
2 Replies

6. Shell Programming and Scripting

How to separate file to multiple line.

Hi Unix gurus, I am facing a problme with file. I need separate my file into multiple line. eg. Soure file: PRT07, aaa, bbb, 46, PRT06, ccc, ddd, 57, PRT05, eee,fff,aa, target file: PRT07, aaa, bbb, 46 PRT06, ccc, ddd, 57 PRT05, eee,fff,aa :wall: thanks in advance (4 Replies)
Discussion started by: ken002
4 Replies

7. Shell Programming and Scripting

Read file contents and separate the lines when completes with =

Hi, I have a file like this cpsSystemNotifyTrap='2010/12/14 11:05:31 CST' Manufacturer=IBM ReportingMTMS=n/a ProbNm=26 LparName=n/a FailingEnclosureMTMS=7946-IQL*99G4874 SRC=B3031107 EventText=Problem reported by customer. CallHome=true Calendar I want to have a output like this... (6 Replies)
Discussion started by: dbashyam
6 Replies

8. Shell Programming and Scripting

extract nth line of all files and print in output file on separate lines.

Hello UNIX experts, I have 124 text files in a directory. I want to extract the 45678th line of all the files sequentialy by file names. The extracted lines should be printed in the output file on seperate lines. e.g. The input Files are one.txt, two.txt, three.txt, four.txt The cat of four... (1 Reply)
Discussion started by: yogeshkumkar
1 Replies

9. Shell Programming and Scripting

Read 1-line file and separate into multiple variables

I have one line files with 17 records separated by a semi-colon. I need to create a variable from each record, which I can do via a separate awk for each one, but I know there has to be a better way. Along with pulling out the variable, I need to convert some url coding like a + to a space, etc.... (4 Replies)
Discussion started by: numele
4 Replies

10. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies
Login or Register to Ask a Question