Split one large .csv file in to multiple csv files based on row count using c# - c#-4.0

I have CSV file with below data. I need to split based on row count using c#.
H1,H2,H3,H4,H5
1,2,3,4,5
12,11,8,7,6
23,23,34,1,0
23,23,32,1,0
For example, if row count is 2. It will split in two files
File1.csv (first two records)
H1,H2,H3,H4,H5
1,2,3,4,5
12,11,8,7,6
File2.csv (Next two records)
H1,H2,H3,H4,H5
23,23,34,1,0
23,23,32,1,0
Can anyone help on this.
Thanks

Related

file Columns not append correctly

I try to append below 2 files' data. But the column "ytd" is appended in different column. And the columns reorder by alphabet. Would appreciate some guidance on how to keep the columns order as the original file and make the ytd column of the 2 files together. Many thanks
My code is as below:
dfaq=pd.read_csv('aq2.csv')
dfmg1=pd.read_csv('test10320_2.csv')
dfaq1=dfmg1.append(dfaq, ignore_index=True)
aq.csv
mg10320.csv
** incorrect Result**

Combine multiple files csv into one using awk

I want to combine two .csv files based on the unique id that exists in both files.
First file consist of 17 columns and the second one in 2 columns where in both files the first column is the same unique id.
In the to be created file 3 i would like 18 columns.
I have been trying paste
paste -d ' ' SPOOL1.csv SPOOL2.csv > MERGED.csv
but that of course does not take the unique columns into consideration.
Not proficient in awk so all help is appreciated.
Thanks
sounds like if the files are sorted then
join SPOOL1 SPOOL2 > MERGED
should get you closer if you deal with the delimiters not shown

How can I add comments at the top of data file that I have created using savetxt function in python 3.0?

Using the savetxt function, I created a data file named as 'output.dat' to which two arrays were written as two different columns. So the file output.dat contains 2 columns of data. Now I want to add headings at the top of each column that would help me to remind what the file contains when I refer back the file later. Say, I want to put the heading 'Time' on the top of the first column and 'Voltage' on the top of the second. How can I do this?

Combine first two columns of a single csv file into another column

So I have a large CSV file (in Gb) where I have multiple columns, the first two columns are :
Invoice number|Line Item Number
I want a unix / linux /ubuntu command which can merge this two columns and create a new column which is separated by separator ':', so for eg : If invoice number is 64789544 and Line Item Number is 234533, then my Merged value should be
64789544:234533
Can it really be achieved, If yes can the merged column is possible to be added back to the source csv file.
You can use the following sed command:
$ cat large.csv
Invoice number|Line Item Number|Other1|Other2
64789544|234533|abc|134
64744123|232523|cde|awc
$ sed -i.bak 's/^\([^|]*\)|\([^|]*\)/\1:\2/' large.csv
$ cat large.csv
Invoice number:Line Item Number|Other1|Other2
64789544:234533|abc|134
64744123:232523|cde|awc
Just be aware that it will take a backup of your input file just in case so you need to have enough space in your file system.
Explanations:
s/^\([^|]*\)|\([^|]*\)/\1:\2/ this command will replace the first two field of your CSV separated by | and will replace the separator by : using back references what will merge the 2 columns.
If you are sure about what you are doing, you can change -i.bak in -i to avoid taking a backup of the CSV file.
Perhaps with this simple sed
sed 's/|/:/' infile

How to get a count of same values in the same column of two files in linux shell?

If you have two files of the same tab separated format, and you want to get a count of how many values in that column are the same between the two files, what would be the best way to do that?
Example:
I have five columns of tab separated data, column two file1 is as follows:
234839
349583
444995
694038
785948
and in file2 column 2 is this:
123943
234839
338273
349583
785948
The expected output would be 3.
Depends, do you want to have a mapping between between values and counts, or is the value one of the inputs?
Either way you can probably do it by piping cat, cut, grep, wc -l

Resources