Sponsored Content
Top Forums Shell Programming and Scripting How to split one record to multiple records? Post 302923457 by jaggy on Monday 3rd of November 2014 05:03:00 AM
Old 11-03-2014
How to split one record to multiple records?

Hi,
I have one tab delimited file which is having multiple store_ids in first column seprated by pipe.I want to split the file on the basis of store_id(separating 1st record in to 2 records ).
I tried some more options like below with using split,awk etc ,But not able to get proper output. can somebody please help here?

Code:
awk 'FS = "\t";{n=split($2,s,"|");for (i=1;i<=n;i++) {$2=s[i];print}}'

Code:
Input:
store_id	Age_21_25	Age_26_35	Age_36_45	Age_46_55	Age_56_65
1000401164|689017	8.116937952	41.8758236	24.30776271	11.95505201	8.471244693
1000488334|1084206	7.114212034	57.5707557	17.80863244	8.561672677	4.061502426
1000774612|1125312	6.4755786	63.15054848	15.40059325	7.036513624	5.047765246
1000979214|1190013	6.181663241	44.56080063	21.15212533	13.05156994	9.326079288
|1081832	6.810393524	39.3111534	23.87784902	15.98099337	9.4109512
2000043615|970276	6.809158988	51.58667473	19.64147383	9.620136197	7.546592693
2000136868|8065019	9.962407379	37.94331719	19.7381623	14.41566889	11.06586732
2000186586|8075300|123456	7.13703001	38.0685379	23.06179155	14.16599508	10.76015759

Code:
output:
store_id	Age_21_25	Age_26_35	Age_36_45	Age_46_55	Age_56_65
1000401164	8.116937952	41.8758236	24.30776271	11.95505201	8.471244693
689017	8.116937952	41.8758236	24.30776271	11.95505201	8.471244693
1000488334	7.114212034	57.5707557	17.80863244	8.561672677	4.061502426
1084206	7.114212034	57.5707557	17.80863244	8.561672677	4.061502426
1000774612	6.4755786	63.15054848	15.40059325	7.036513624	5.047765246
1125312	6.4755786	63.15054848	15.40059325	7.036513624	5.047765246
1000979214	6.181663241	44.56080063	21.15212533	13.05156994	9.326079288
1190013	6.181663241	44.56080063	21.15212533	13.05156994	9.326079288
1081832	6.810393524	39.3111534	23.87784902	15.98099337	9.4109512
2000043615	6.809158988	51.58667473	19.64147383	9.620136197	7.546592693
970276	6.809158988	51.58667473	19.64147383	9.620136197	7.546592693
2000136868	9.962407379	37.94331719	19.7381623	14.41566889	11.06586732
8065019	9.962407379	37.94331719	19.7381623	14.41566889	11.06586732
2000186586	7.13703001	38.0685379	23.06179155	14.16599508	10.76015759
8075300	7.13703001	38.0685379	23.06179155	14.16599508	10.76015759
123456	7.13703001	38.0685379	23.06179155	14.16599508	10.76015759

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to split multiple records file in n files

Hello, Each record has a lenght of 7 characters I have 2 types of records 010 and 011 There is no character of end of line. For example my file is like that : 010hello 010bonjour011both 011sisters I would like to have 2 files 010.txt (2 records) hello bonjour and ... (1 Reply)
Discussion started by: jeuffeu
1 Replies

2. Shell Programming and Scripting

Parsing record into multiple records in Shell Script

Hi, I am trying to parse a very long record in a text file into multiple records by checking ADD, DELETE, or MODIFY field value in a shell script. Input # File name xyz.txt ADD|N000|8015662|DELETE|N001|9915662|MODIFY|N999|85678 Output ADD|N000|8015662| DELETE|N001|9915662|... (8 Replies)
Discussion started by: naveed
8 Replies

3. Shell Programming and Scripting

Multiple records based on ';' in the record

Hi All, I have a *.csv files in a die /pro/lif/dow, (pipe delimiter file), these files are having 8 columns and 6 column(CDR_LOGIC) records are populated as below, I need to incorporate the below logic in all the *.csv files. 11||:ColumnA||:ColumnB 123||:ColumnA IIF(:ColumnA = :ColumnC then... (6 Replies)
Discussion started by: shruthidwh
6 Replies

4. Shell Programming and Scripting

Split a single record to multiple records & add folder name to each line

Hi Gurus, I need to cut single record in the file(asdf) to multile records based on the number of bytes..(44 characters). So every record will have 44 characters. All the records should be in the same file..to each of these lines I need to add the folder(<date>) name. I have a dir. in which... (20 Replies)
Discussion started by: ram2581
20 Replies

5. Shell Programming and Scripting

reformat one record from two records

I have not get much answer/solution for the posting. Here I break down the question and hope to get some help. 1. How can I use AWK to read in two records at the same time and keep loop to next two when the condition is meet? position 1-10 --> Unique to identity whether... (4 Replies)
Discussion started by: menglm
4 Replies

6. UNIX for Dummies Questions & Answers

Split single record to multiple records

Hi Friends, source .... col1,col2,col3 a,b,1;2;3 here colom delimeter is comma(,). here we dont know what is the max length of col3 means now we have 1;2;3 next time i will receive 1;2;3;4;5;etc... required output .............. col1,col2,col3 a,b,1 a,b,2 a,b,3 please give me... (5 Replies)
Discussion started by: bab.galary
5 Replies

7. Shell Programming and Scripting

Split records into multiple records

Hi All, I am trying to split a record into multiple records based on a value. Input.txt "A",1,0,10 "B",2,0,10,15,20 "C",3,11,14,16,19,21,23 "D",1,0,5 My desired output is: "A",1,0,10 "B",2,0,10 "B",2,15,20 "C",3,11,14 "C",3,16,19 "C",3,21,23 (4 Replies)
Discussion started by: kmsekhar
4 Replies

8. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

9. Shell Programming and Scripting

Multiple Records from 1 Record

I need to make one record to multiple records based on occurence column in the record and change the date.For example below first record has 5 ,so need to create 5 records from one and change the date to 5 months.Occurence can be any number. I am unable to come with a script.Can some one help ... (5 Replies)
Discussion started by: traininfa
5 Replies

10. Shell Programming and Scripting

Split a large file in n records and skip a particular record

Hello All, I have a large file, more than 50,000 lines, and I want to split it in even 5000 records. Which I can do using sed '1d;$d;' <filename> | awk 'NR%5000==1{x="F"++i;}{print > x}'Now I need to add one more condition that is not to break the file at 5000th record if the 5000th record... (20 Replies)
Discussion started by: ibmtech
20 Replies
MPB(1)							    MIT Photonic-Bands Package							    MPB(1)

NAME
mpb-split - compute eigenmodes with MPB using multiple processes SYNOPSIS
mpb-split NUM-SPLIT [DEFINITION]... [CTLFILE]... DESCRIPTION
mpb-split is a parallelizing front-end to MIT Photonic Bands (MPB). For a computation with several k points, it splits the list of k points over multiple processes. Of course, this will only benefit you on a system where different processes will run on different proces- sors, such as an SMP or a cluster with automatic process migration (e.g. MOSIX). mpb-split is actually a trivial shell script, though, so you can easily modify it if you need to use a special command to launch processes on other processors/machines. MIT Photonic Bands (MPB) is a free program to compute the band structures (dispersion relations) and electromagnetic modes of periodic dielectric structures, and is applicable both to photonic crystals (photonic band-gap materials) and a wide range of other optical prob- lems. More information on MPB, including a detailed manual, can be found online at the MPB home page: http://ab-initio.mit.edu/mpb/ A typical invocation of mpb-split looks like: mpb-split num-split foo.ctl >& foo.out This causes mpb-split to process the control file foo.ctl, divide the k points into num-split equal chunks, run each list in a separate process with MPB, and redirect the output (in order) to foo.out. (One typically redirects output to a file, as the output is verbose and contains a number of comma-delimited datasets that one can extract by grepping.) Overall, the behavior and arguments are the same as for mpb except that the first argument must be the integer num-split. What mpb-split technically does is to set the MPB variable k-split-num to num-split and k-split-index to the index (starting with 0) of the chunk for each process. If you want, you can use these variables to divide the problem in some other way and then reset them to 1 and 0, respectively. BUGS
Send bug reports to S. G. Johnson, stevenj@alum.mit.edu. AUTHORS
Written by Steven G. Johnson. Copyright (c) 1999, 2000, 2001, 2002 by the Massachusetts Institute of Technology. SEE ALSO
mpb(1), mpb-data(1) MPB
March 13, 2002 MPB(1)
All times are GMT -4. The time now is 07:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy