Sponsored Content
Top Forums Shell Programming and Scripting Remove the values from a certain column without deleting the Column name in a .CSV file Post 302880260 by disedorgue on Wednesday 18th of December 2013 11:53:19 AM
Old 12-18-2013
Hi, example with sed:
Code:
$ cat fich.csv
name1,name2,name3,name4,name5,name6,name7,name8,name9,name10,
val1,val2,val3,val4,val5,val6,val7,val8,val9,val10,
valx1,valx2,valx3,valx4,valx5,valx6,valx7,valx8,valx9,valx10,
valy1,valy2,valy3,valy4,valy5,valy6,valy7,valy8,valy9,valy10,
valz1,valz2,valz3,valz4,valz5,valz6,valz7,valz8,valz9,valz10,

Code:
$ sed '1!s/\(\([^,]*,\)\{4\}\)[^,]*/\1/' fich.csv
name1,name2,name3,name4,name5,name6,name7,name8,name9,name10,
val1,val2,val3,val4,,val6,val7,val8,val9,val10,
valx1,valx2,valx3,valx4,,valx6,valx7,valx8,valx9,valx10,
valy1,valy2,valy3,valy4,,valy6,valy7,valy8,valy9,valy10,
valz1,valz2,valz3,valz4,,valz6,valz7,valz8,valz9,valz10,

Regards.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, My requirement is to remove line (3 Replies)
Discussion started by: r_t_1601
3 Replies

2. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, i have a csv file . In the 7th column i have data that has line feed in it. Requirement is to remove the line feed from the 7th column whenever it appears There are 11 columns in the file C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 The value in C7 contains line feed ( Alt + Enter ),... (2 Replies)
Discussion started by: r_t_1601
2 Replies

3. Shell Programming and Scripting

How to avoid Delimiter occuring in column values in .csv file

Hello Gurus, I need to create a file from a .csv file extracting specific columns only. File structure is Column1,Column2,Column3,Column4 abcd,1234,"asdf, tew,123",123456 efgh,234,asdf,654321 My output file should have abcd,123456 efgh,654321 Can you pls help me with the code. ... (10 Replies)
Discussion started by: ritesh.bhawsar
10 Replies

4. Shell Programming and Scripting

Check to identify duplicate values at first column in csv file

Hello experts, I have a requirement where I have to implement two checks on a csv file: 1. Check to see if the value in first column is duplicate, if any value is duplicate script should exit. 2. Check to verify if the value at second column is between "yes" or "no", if it is anything else... (4 Replies)
Discussion started by: avikaljain
4 Replies

5. Linux

Filter a .CSV file based on the 5th column values

I have a .CSV file with the below format: "column 1","column 2","column 3","column 4","column 5","column 6","column 7","column 8","column 9","column 10 "12310","42324564756","a simple string with a , comma","string with or, without commas","string 1","USD","12","70%","08/01/2013",""... (2 Replies)
Discussion started by: dhruuv369
2 Replies

6. Shell Programming and Scripting

Fetching values in CSV file based on column name

input.csv: Field1,Field2,Field3,Field4,Field4 abc ,123 ,xyz ,000 ,pqr mno ,123 ,dfr ,111 ,bbb output: Field2,Field4 123 ,000 123 ,111 how to fetch the values of Field4 where Field2='123' I don't want to fetch the values based on column position. Instead want to... (10 Replies)
Discussion started by: bharathbangalor
10 Replies

7. Linux

To get all the columns in a CSV file based on unique values of particular column

cat sample.csv ID,Name,no 1,AAA,1 2,BBB,1 3,AAA,1 4,BBB,1 cut -d',' -f2 sample.csv | sort | uniq this gives only the 2nd column values Name AAA BBB How to I get all the columns of CSV along with this? (1 Reply)
Discussion started by: sanvel
1 Replies

8. Shell Programming and Scripting

Identify duplicate values at first column in csv file

Input 1,ABCD,no 2,system,yes 3,ABCD,yes 4,XYZ,no 5,XYZ,yes 6,pc,noCode used to find duplicate with regard to 2nd column awk 'NR == 1 {p=$2; next} p == $2 { print "Line" NR "$2 is duplicated"} {p=$2}' FS="," ./input.csv Now is there a wise way to de-duplicate the entire line (remove... (4 Replies)
Discussion started by: deadyetagain
4 Replies

9. Shell Programming and Scripting

Remove duplicate values in a column(not in the file)

Hi Gurus, I have a file(weblog) as below abc|xyz|123|agentcode=sample code abcdeeess,agentcode=sample code abcdeeess,agentcode=sample code abcdeeess|agentadd=abcd stereet 23343,agentadd=abcd stereet 23343 sss|wwq|999|agentcode=sample1 code wqwdeeess,gentcode=sample1 code... (4 Replies)
Discussion started by: ratheeshjulk
4 Replies
NCFLINT(1)						      General Commands Manual							NCFLINT(1)

NAME
ncflint - netCDF File Interpolator SYNTAX
ncflint [-3] [-4] [-6] [-A] [-C] [-c] [-D dbg] [-d dim,[ min][,[ max]]] [-F] [-h] [-i var,val3][-L dfl_lvl][-l path] [-O] [-p path] [-R] [-r] [-t thr_nbr] [-v var[,...]] [-w wgt[, wgt2]] [-X box] [-x] file1 file2 file3 DESCRIPTION
ncflint creates an output file that is a linear combination of the input files. This linear combination can be a weighted average, a nor- malized weighted average, or an interpolation of the input files. Coordinate variables are not acted upon in any case, they are simply copied from file_1. There are two conceptually distinct methods of using ncflint. The first method is to specify the weight each input file is to have in the output file. In this method, the value val3 of a variable in the output file file_3 is determined from its values val1 and val2 in the two input files according to wgt1*val1+wgt2*val2 Here at least wgt1, and, optionally, wgt2, are specified on the command line with the -w (or --weight or --wgt_var ) switch. If only IR wgt1 is specified then wgt2 is automatically computed as wgt2=1-wgt1. Note that weights larger than 1 are allowed. Thus it is possible to specify wgt1=2 and wgt2=-3. One can use this functionality to multiply all the values in a given file by a constant. The second method of using ncflint is to specify the interpolation option with -i (or with the --ntp or --interpolate long options). This is really the inverse of the first method in the following sense. When the user specifies the weights directly, ncflint has no work to do besides multiplying the input values by their respective weights and adding the results together to produce the output values. This assumes it is the weights that are known a priori. In another class of cases it is the "arrival value" (i.e., val3 ) of a particular vari- able var that is known a priori. In this case, the implied weights can always be inferred by examining the values of var in the input files. This results in one equation in two unknowns, wgt1 and wgt2: val3=wgt1*val1+wgt2*val2. Unique determination of the weights requires imposing the additional constraint of normalization on the weights: wgt1+wgt2=1. Thus, to use the interpolation option, the user specifies var and val3 with the -i option. ncflint will compute wgt1 and wgt2, and use these weights on all variables to generate the output file. Although var may have any number of dimensions in the input files, it must represent a single, scalar value. Thus any dimensions associated with var must be "degenerate", i.e., of size one. If neither -i nor -w is specified on the command line, ncflint defaults to weighting each input file equally in the output file. This is equivalent to specifying -w0.5 or -w0.5,0.5. Attempting to specify both .BR -i and -w methods in the same command is an error. ncflint is programmed not to interpolate variables of type NC_CHAR and NC_BYTE. This behavior is hardcoded. AUTHOR
NCO manual pages written by Charlie Zender and Brian Mays. REPORTING BUGS
Report bugs to <http://sf.net/bugs/?group_id=3331>. COPYRIGHT
Copyright (C) 1995-2010 Charlie Zender This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for NCO is maintained as a Texinfo manual called the NCO User's Guide. Because NCO is mathematical in nature, the documentation includes TeX-intensive portions not viewable on character-based displays. Hence the only complete and authoritative versions of the NCO User's Guide are the PDF (recommended), DVI, and Postscript versions at <http://nco.sf.net/nco.pdf>, <http://nco.sf.net/nco.dvi>, and <http://nco.sf.net/nco.ps>, respectively. HTML and XML versions are available at <http://nco.sf.net/nco.html> and <http://nco.sf.net/nco.xml>, respectively. If the info and NCO programs are properly installed at your site, the command info nco should give you access to the complete manual, except for the TeX-intensive portions. HOMEPAGE
The NCO homepage at <http://nco.sf.net> contains more information. NCFLINT(1)
All times are GMT -4. The time now is 10:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy