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
(3)							      Free Widget Foundation							       (3)

NAME
XltFontChooser DESCRIPTION
The XltFontChooser widget allows a user to select a font by choosing its XLFD font name fields. The widget is subclassed from XmMessageBox which means it inherits its behavior. This is a rather simple widget (less than 600 lines), it can create a hell of a widget hierarchy though. Editres will amaze you. Public variables +-----------------------------------------------------------------------------------------------+ | | | XltFontChooser | |Name | Class | Type | Default | |XltNshowDemo | XltCShowDemo | Boolean | True | |XltNfontName | XltCFontName | String | NULL | |XltNdemoString | XltCDemoString | String | "The quick brown fox jumps over the lazy dog." | |XltNcountString | XltCCountString | String | "%d matching fonts" | |XltNpattern | XltCPattern | String | "-*-*-*-*-*-*-*-*-*-*-*-*-*-*" | |XltNsortCriteria | XltNSortCriteria | String | "aaaaaannnnanaa" | | | | | | +-----------------+------------------+---------+------------------------------------------------+ XltNshowDemo Whether to show a string in the font selected by the user. (Or the first one that applies the selection, if multiple). XltNfontName This is the name of the selected font. XltNdemoString This string is shown to demonstrate the selected font. XltNcountString This string is used to print the amount of matching fonts. XltNpattern This string is used to specify the initial query for fonts. The default value will retrieve all fonts with XLFD compliant names. XltNsortCriteria This string of exactly 14 characters indicates the sorting order used for the menu buttons. n or N mean numeric, a or A indicate alphabetic sort order, any other character means don't sort. Selected inherited resources XmNokCallback Allows an application to get a call, query XltNfontName using GetValues, and take appropriate action. XmNcancelCallback CLASS HIERARCHY
These manuals of the superclasses describe the inherited resources : Object(3) Rect(3) UnNamedObj(3) Core(3) XmManager(3) XmBulletinBoard(3) XmMessageBox(3) Version 3.0 (3)
All times are GMT -4. The time now is 11:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy