Sponsored Content
Full Discussion: Combined Two CSV Lines
Top Forums Shell Programming and Scripting Combined Two CSV Lines Post 302570530 by thegeek on Thursday 3rd of November 2011 01:42:03 PM
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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
HASH_UPDATE_STREAM(3)							 1						     HASH_UPDATE_STREAM(3)

hash_update_stream - Pump data into an active hashing context from an open stream

SYNOPSIS
int hash_update_stream (resource $context, resource $handle, [int $length = -1]) DESCRIPTION
PARAMETERS
o $context - Hashing context returned by hash_init(3). o $handle - Open file handle as returned by any stream creation function. o $length - Maximum number of characters to copy from $handle into the hashing context. RETURN VALUES
Actual number of bytes added to the hashing context from $handle. EXAMPLES
Example #1 hash_update_stream(3) example <?php $fp = tmpfile(); fwrite($fp, 'The quick brown fox jumped over the lazy dog.'); rewind($fp); $ctx = hash_init('md5'); hash_update_stream($ctx, $fp); echo hash_final($ctx); ?> The above example will output: 5c6ffbdd40d9556b73a21e63c3e0e904 SEE ALSO
hash_init(3), hash_update(3), hash_final(3), hash(3), hash_file(3). PHP Documentation Group HASH_UPDATE_STREAM(3)
All times are GMT -4. The time now is 07:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy