Sponsored Content
Full Discussion: Repeating Multiple Fields
Top Forums Shell Programming and Scripting Repeating Multiple Fields Post 302914054 by DerangedNick on Thursday 21st of August 2014 02:13:22 PM
Old 08-21-2014
Repeating Multiple Fields

I am trying to find a way to repeat fields. I am not really sure how to explain it so let me just post a sample and what I want it to look like.

Code:
888123 66232 18 1
                      19 
            44422 11 7
                      23 
881133 66231 33 1
                      34 
983333 11112 11 1
                      34 
            13331 33 11
                      88
                      99 16
                      77
                      11
            33311 33 33

While the sample here is all the same length, the actual values will vary and contain periods, but that shouldn't matter. It will all be separated by spaces but I can put commas or pipes in between if that matters. Here is what the final product would look like.

Code:
1,888123,6623218,1
2,888123,6623219,1
3,888123,4442211,7
4,888123,4442223,7
5,881133,6623133,1
6,881133,6623134,1
7,983333,1111211,1
8,983333,1111234,1
9,983333,1333133,11
10,983333,1333188,11
11,983333,1333199,16
12,983333,1333177,16
13,983333,1333111,16
14,983333,3331133,33

Fields 1, 2 and 4 will change all over the place. So Field 1 should repeat until it is no longer blank (IE it changes), Field 2 repeat until it changes, Field 4 repeat until it changes. Field 3 will always be populated.

Final output would be numbered, then a comma, then Field 1, then a comma, Field2&3 together, then comma and then finally field 4.

I hope I explained that well enough and appreciate any help. The file is about half a million lines.

Thanks

Trying to figure out a way to do it, I think there has to be a separator besides spaces, so the file will look as follows:

Code:
888123|66232|18|1
           |         |19| 
           |44422|11|7
           |         |23|
881133|66231|33|1
           |         |34|
983333|11112|11|1
           |         |34|
           |13331|33|11
           |         |88|
           |         |99|16
           |         |77|
           |         |11|
           |33311|33|33

I can't think of a way of even trying it without a separator, so I recreated the original file like that. Hopefully that makes it easier. Also when I submit this it is moving the text over a bit, but it will all be left justified.

Last edited by DerangedNick; 08-21-2014 at 03:30 PM.. Reason: Notes - Thoughts
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

join on multiple fields

Is it possible to do a join on multiple fields of two files? I am trying to do something like join -t, -1 2,3 -2 2,3 -o 2.1,2.2,2.3,1.3 filea fileb I want the join to be on columns 2 and 3 of filea and columns 2 and 3 of fileb. What is hapenning is that the second file that I want to do the join... (1 Reply)
Discussion started by: reggiej
1 Replies

2. Shell Programming and Scripting

sort on multiple fields

hello all I have a file names xxx with data like 1,2,3,12 1,3,6,12 1,3,5,12 2,4,6,12 6,5,6,12 4,2,7,12 4,1,3,12 I wish to sort this file xxx on first three fields in ascending order. OUPUT should be like 1,2,3,12 1,3,5,12 1,3,6,12 2,4,6,12 (4 Replies)
Discussion started by: vasuarjula
4 Replies

3. Shell Programming and Scripting

sort on multiple fields

Hello All I have data in a flat file with numeric and aplha numeric datatypes. Now i have to sort on multiple fileds. Can any body please give me the sort code? i am particularly confused about the sort code like sort -n +0 -1 +1 -2 .... (1 Reply)
Discussion started by: vasuarjula
1 Replies

4. UNIX for Dummies Questions & Answers

Need help with Join on multiple fields

Hi, I need help with the join command I have 2 files that I want to join on multiple fields. I want to return all records from file 1 I also want empty fields in my joined file if there isn't a match in file 2 I have already sorted them so I know they are in the same order. file1 ... (0 Replies)
Discussion started by: shunter0810
0 Replies

5. UNIX for Dummies Questions & Answers

Formatting Multiple fields on 1 line to multiple rows

I'm trying extract a number of filename fields from a log file and copy them out as separate rows in a text file so i can load them into a table. I'm able to get the filenames but the all appear on one line. I tried using the cut command with the -d (delimiter) option but cant seem to make it... (1 Reply)
Discussion started by: Sinbad-66
1 Replies

6. UNIX for Dummies Questions & Answers

Using sed command to remove multiple instances of repeating headers in one file?

Hi, I have catenated multiple output files (from a monte carlo run) into one big output file. Each individual file has it's own two line header. So when I catenate, there are multiple two line headers (of the same wording) within the big file. How do I use the sed command to search for the... (1 Reply)
Discussion started by: rebazon
1 Replies

7. Shell Programming and Scripting

Matching multiple fields from two files and then some?

Hi, I am working with two tab-delimited files with multiple columns, formatted as follows: File 1: >chrom 1 100 A G 20 …(10 columns) >chrom 1 104 G C 18 …(10 columns) >chrom 2 28 T C ... (4 Replies)
Discussion started by: mbp
4 Replies

8. Shell Programming and Scripting

Sed replace using same pattern repeating multiple times in a line

Sed replace using same pattern repeating multiple times in a line I have text like below in a file: I am trying to replace the above line to following How can I acheive this? I am able to do it if the occurrence is for 1 time: But If I try like below I am getting like this: I have to... (4 Replies)
Discussion started by: sol_nov
4 Replies

9. Shell Programming and Scripting

Deriving unique entries from multiple repeating patterns

Dear All, I have a below one column data.(example) Col1 1 2 . . 25 8 9 25 1 2 . . 25 Where each entry(row) is a number from 1-25, but in place whereever mentioned with . we have all the entries 1-25, but some places where ever no . like in 8 9 25 I have only 3 entries. No I... (14 Replies)
Discussion started by: ks_reddy
14 Replies

10. Shell Programming and Scripting

Getting fields from a file having multiple delimiters

Hi All, I have a file with a single row having the following text ABC.ABC.ABC,Database,New123,DBNAME,F,ABC.ABC.ABC_APP,"@FUNCTION1("ENT1") ,@FUNCTION2("ENT2")",R, I want an output in the following format ABC.ABC.ABC DBNAME ABC.ABC.ABC_APP '@FUNCTION1("ENT1")... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies
HOTSWAPRC(5)							File Formats Manual						      HOTSWAPRC(5)

NAME
hotswaprc - configuration file for hotswap DESCRIPTION
/etc/hotswaprc is the global configuration file for the hotswap utility. It allows system administrators to specify arbitrary shell scripts to be run after a device is inserted, as well as before and after it is removed. Scripts are selected according to the model name retrieved from the device. This is particularly helpful for automatic configura- tion of CD-RW drives, which require SCSI emulation and bypass normal access via the IDE subsystem. hotswaprc is implemented as an Extensible Mark-up Language (XML) application. XML documents are structured using elements of the form <tag-name> content <tag-name>. A Document Type Definition (DTD) describes the possible content of each element. Please refer to the XML specification for more information. The hotswap distribution also contains an example file, doc/hotswaprc.example, which includes the DTD for the configuration file format. ELEMENTS
<hotswap> This is the root element of the document. Each valid hotswaprc must contain exactly one <hotswap> element. The <hotswap> element may contain an arbitrary number of <device> elements. <device> The configuration file contains one <device> element for every device for which scripts are defined. The <device> element is com- posed of the following elements in this order: <name>, <post-insert>, <pre-remove>, <post-remove>. All but <name> are optional. <name> The content of this element is the model identification string of the IDE device the current <device> element refers to. <post-insert> Contains the shell script that is to be executed after the device has been inserted and registered with the kernel. <pre-remove> Contains the shell script that is to be run before hotswap attempts to unregister the device. <post-remove> Contains the shell script that is to be run after the device had been unregistered. REPORT BUGS
Report bugs to t.stadelmann1@physics.ox.ac.uk. AUTHOR
Written by Tim Stadelmann. SEE ALSO
hotswap(1), xhotswap(1). COPYRIGHT
Copyright (c) 2002-2003 Tim Stadelmann. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License (GPL), Version 2 or any later version published by the Free Software Foundation. 26th November 2002 HOTSWAPRC(5)
All times are GMT -4. The time now is 06:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy