Combined Two CSV Lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combined Two CSV Lines
# 1  
Old 11-03-2011
Here is another way:


Code:
@line1 = split /,/, <DATA>;
@line2 = split /,/, <DATA>;

for (0..$#line1)  {
    if ( $line1[$_] =~ /^\s*$/ )  {
        print $line2[$_] if ( defined $line2[$_] );
    } else {
        print $line1[$_];
    }
    print "," if ( $_ != $#line1 );
}

__DATA__
the,quick,brown,fox,,jumps,,the,,dog
the,quick,brown,fox,,,over,,lazy,dog

Which actually prints this,
Code:
the,quick,brown,fox,,jumps,over,the,lazy,dog

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert a horizontal lines to vertical lines in a csv file

Hi.. I need some help in converting the below horizontal lines to vertical lines format. can anyone help me on this. input file Hour,1,2,3,4,5 90RT,106,111,111,112,111 output file Hour,90RT 1,106 2,111 3,111 4,112 5,111 (3 Replies)
Discussion started by: Raghuram717
3 Replies

2. UNIX for Beginners Questions & Answers

Duplicate specifc lines in csv

Hi, I want to duplicate lines of a csv file with header if a column has multiple values. The csv uses semicolon as separator while multiple values are separated with comma. Only the type3 column can have multiple values. input: type1;type2;type3 a1;b1;x,y a2;b2;z output: a1;b1;x... (2 Replies)
Discussion started by: iz_82
2 Replies

3. Shell Programming and Scripting

Combined sed+awk for lookup csv file

have written a combined sed+awk to perform a lookup operation which works but looking to enhance it. looking to match a record using any of the comma separated values + return selected fields from the record - including the field header. so: cat foo make,model,engine,trim,value... (6 Replies)
Discussion started by: jack.bauer
6 Replies

4. Shell Programming and Scripting

Filtering out lines in a .csv file

Hi Guys, Would need your expert help with the following situation.. I have a comma seperated .csv file, with a header row and data as follows H1,H2,H3,H4,H5..... (header row) 0,0,0,0,0,1,2.... (data rows follow) 0,0,0,0,0,0,1 ......... ......... i need a code... (10 Replies)
Discussion started by: dev.devil.1983
10 Replies

5. Shell Programming and Scripting

Trying to combine 2 lines into one CSV format

Hi, I have the following test script I'm working with: date +"%m-%d-%y">>test.log grep eth0 /proc/net/dev | awk '{print ",",$2/1024/1024,",",$10/1024/1024}'>>test.log The output looks like this: 02-25-12 , 19.3581 , 84.2826 02-25-12 , 19.3587 , 84.283 02-25-12 , 19.3587 ,... (4 Replies)
Discussion started by: nbsparks
4 Replies

6. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

7. Shell Programming and Scripting

Removing lines of a .csv file

Hello, Does anyone have a one-liner to remove lines of a csv file if the value in a specific column is zero? For example, I have this file, 12345,COM,5,0,N,29.95,Y 12345,MOM,1,0,N,29.95,Y 12345,COM,4,0,N,9.99,Y 12345,MOM,0,2,N,9.99,Y 12345,REN,0,1,N,9.99,Y and I want to remove lines... (4 Replies)
Discussion started by: palex
4 Replies

8. Shell Programming and Scripting

Multiple lines combined into one for netstat (or ls)

Hello So I understand when I do the following used_ports=$(netstat -nat |cut -d : -f 2 |cut -d ' ' -f 1) that the output will look like this Active Proto 5298 22 631 55012 56093 39672 43196 56619 39677 36103 38453 41413 56137 37902 41410 41414 43195 38426 49253 38420 34273 ... (1 Reply)
Discussion started by: brsett
1 Replies

9. Shell Programming and Scripting

Deleting Lines from .CSV Files

I have written an script which will excluded some records from .csv file and put it on another excluded file from primary file.This is working very fine.Now the problem is that I want to delete those excluded lines from Primary file but not able to delete it. I have stored the line number in... (1 Reply)
Discussion started by: 009satya
1 Replies

10. Shell Programming and Scripting

Getting variables out of .csv lines

I have a csv file looking like: echo,w-cai,w-cai-ssl echo,countrywide,countrywide-ssl haystack,intranet3,intranet3-ssl haystack,pnf,pnf-ssl Basically, I want to process this file row by row assigning each word delimited by a comma to a variable. ie. for the first row, $variable1=echo... (5 Replies)
Discussion started by: Sn33R
5 Replies
Login or Register to Ask a Question
DtEditorSetContents(library call)										 DtEditorSetContents(library call)

NAME
DtEditorSetContents -- place data into a DtEditor widget SYNOPSIS
#include <Dt/Editor.h> DtEditorErrorCode DtEditorSetContents( Widget widget, DtEditorContentRec *data); DESCRIPTION
The DtEditorSetContents function places a NULL-terminated string, wide character string or sized buffer into a DtEditor widget. Any data currently in the DtEditor widget is lost. The data is transferred to the DtEditor widget using a DtEditorContentRec, which indicates the type of data being transferred along with the actual data. After the data is placed into the DtEditor widget, the insertion cursor is positioned at the first character. The widget argument specifies the DtEditor widget ID. The data argument is a pointer to a data structure containing the new contents of widget. For a complete definition of the DtEditor widget and its associated resources, see DtEditor(3). For a complete definition of DtEditorContentRec, see Dt/Editor.h - DtEditor(5). RETURN VALUE
Upon successful completion, the DtEditorSetContents function returns one of the following values: DtEDITOR_NO_ERRORS The data was loaded sucessfully. DtEDITOR_NULLS_REMOVED NULL characters were found and removed from the data. Otherwise, if the DtEditorSetContents function cannot load the data in the DtEditor widget, it returns one of the following values: DtEDITOR_INVALID_TYPE The Type field is unrecognized. DtEDITOR_ILLEGAL_SIZE The size of the buffer passed in is negative. DtEDITOR_NULL_ITEM The buffer is NULL. DtEDITOR_INSUFFICIENT_MEMORY Not enough system memory is available to load the data. EXAMPLES
The following code segment sets the contents of a DtEditor widget to ``The quick brown fox.'' Widget editor; DtEditorContentRec cr; DtEditorErrorCode status; char *sampleString="The quick brown fox"; cr.type = DtEDITOR_TEXT; cr.value.string = sampleString; status = DtEditorSetContents(editor, &cr); if (status != DtEDITOR_NO_ERRORS && status != DtEDITOR_NULLS_REMOVED) { printf("Unable to set contents of the widget "); APPLICATION USAGE
If the data is in a disk file, rather than in memory, the application should use DtEditorSetContentsFromFile(3). SEE ALSO
Dt/Editor.h - DtEditor(5), DtEditor(3), DtEditorAppend(3), DtEditorAppendFromFile(3), DtEditorGetContents(3), DtEditorInsert(3), DtEdi- torInsertFromFile(3), DtEditorReplace(3), DtEditorReplaceFromFile(3), DtEditorSaveContentsToFile(3), DtEditorSetContentsFromFile(3). DtEditorSetContents(library call)