Shell code for split/merge the file with certain number of columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell code for split/merge the file with certain number of columns
# 8  
Old 04-26-2014
Hi Srini,
sorry to confusing 1st of al.
let me give exact scenario.

Code:
1242л1242ллллллллллNлллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл0.00ллллллл
1190л1190ллллллллллNлллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл0.00ллллллл
743л743ллллллллллNлллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл0.00ллллллл

above are original src data.(and it should be like this after coding)
the spcl symbl is the delimeter.

due to newline charector in some fields those are brokn into multiple..
lets consider 1st row here.
Code:
1242л12
42ллллллллллN
лллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл0.00ллллллл

above scenario, 2nd field is having newline inbetwn the data. and also after N value again one more newline charecter , so its now again splited to next line.

now requird code is to be merge all the fields by removing newline charectors until it gets 86 fields.

note: as u mentioned every row start with newline only not the case of append with prevuis line.

hope i explain clear.

its very urgent requirment need help ASAP.

thanks in advance.

Last edited by Don Cragun; 04-26-2014 at 02:59 AM.. Reason: Add CODE tags again.
# 9  
Old 04-29-2014
You might try like
Code:
awk -F"л" '{while (NF<85) {getline Y;$0=$0 Y}}1' OFS="л" file
1242л1242ллллллллллNлллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл0.00ллллллл

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 into multiple files by using Unique columns in a UNIX file

I have requirement to split below file (sample.csv) into multiple files by using the unique columns (first 3 are unique columns) sample.csv 123|22|56789|ABCDEF|12AB34|2019-07-10|2019-07-10|443.3400|1|1 123|12|5679|BCDEFG|34CD56|2019-07-10|2019-07-10|896.7200|1|2... (3 Replies)
Discussion started by: RVSP
3 Replies

2. Shell Programming and Scripting

awk split columns to row after N number of column

I want to split this with every 5 or 50 depend on how much data the file will have. And remove the comma on the end Source file will have 001,0002,0003,004,005,0006,0007,007A,007B,007C,007E,007F,008A,008C Need Output from every 5 tab and remove the comma from end of each row ... (4 Replies)
Discussion started by: ranjancom2000
4 Replies

3. Shell Programming and Scripting

Split a non delimited file into columns depending on user input

I would like some advice on some code. I want to write a small script that will take an input file of this format 111222233334444555666661112222AAAA 2222333445556612323244455445454545 2334556345643534505435345353453453 (and so on) It will be called as : script inputfile X (where X is... (5 Replies)
Discussion started by: onlyforbopi
5 Replies

4. Shell Programming and Scripting

Merge 2 last columns in a csv file using sed or perl

Hello everyone, want to merge 2 last columns 3rd and 4rd (if it exists). I have this 1;2;1;1 2;3;1;1 1;1;2 1;2;3;4 1;1;2 1;2;3;1 Desired output: 1;2;1 1 2;3;1 1 1;1;2 1;2;3 4 1;1;2 1;2;3 1 (3 Replies)
Discussion started by: satir
3 Replies

5. Shell Programming and Scripting

Seperated by columns, merge in a file, sort them on common column

Hi All, I have 4 files in below format. I took them as an example. File 1: Cut from position 1-4 then 6-7 then 8-14 then rest left and make them as columns in one new file. Inserting character H to the initial of all line like HCTOT. CTOT 456787897 Low fever CTOR 556712345 High fever... (2 Replies)
Discussion started by: Mannu2525
2 Replies

6. Shell Programming and Scripting

file merge based on common columns

I have two files 1.txt 34, ABC, 7, 8, 0.9 35, CDE, 6.5, -2, 0.01 2.txt 34, ABC, 9, 6, -1.9 35, CDE, 8.5, -2.3, 5.01 So in both files common columns are 1 and 2 so final o/p should look like 34, ABC, 7, 8, 0.9, 9, 6, -1.9 35, CDE, 6.5, -2, 0.01, 8.5, -2.3, 5.01 I tried using... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

7. UNIX for Dummies Questions & Answers

How to split a huge file into small pieces (per 2000 columns)?

Dear all, I have a big file:2879(rows)x400,170 (columns) like below. I 'd like to split the file into small pieces:2879(rows)x2000(columns) per file (the last small piece will be 2879x170. So far, I only know how to create one samll piece at one time. But actually I need to repeat this work... (6 Replies)
Discussion started by: forevertl
6 Replies

8. Shell Programming and Scripting

Split file by number of words

Dear all I am trying to divide a file using the number of words as a condition. Alternatively, I would at least like to be able to retrieve the first x words of a given file. Any tips? Thanks in advance. (7 Replies)
Discussion started by: aavv
7 Replies

9. Shell Programming and Scripting

Split File of Number with spaces

How do i split a variable of numbers with spaces... for example echo "100 100 100 100" > temp.txt as the values can always change in temp.txt, i think it will be feasible to split the numbers in accordance to column. How is it possible to make it into $a $b $c $d? (3 Replies)
Discussion started by: dplate07
3 Replies

10. UNIX for Dummies Questions & Answers

split a file into a specified number of files

I have been googling on the 'split' unix command to see if it can split a large file into 'n' number of files. Can anyone spare an example or a code snippet? Thanks, - CB (2 Replies)
Discussion started by: ChicagoBlues
2 Replies
Login or Register to Ask a Question