retrieve data column wise from csv files
Hi.. i am new to the Linux.i need help.
i want to retrieve data column wise from csv files in shell scripting.pl z help me. my csv file like this "101","a","fs" "102","b","ss" "103","svs","fs,sd" "104","ssvsd","ssSdvs"Sdvs" thanks in advance. |
If every column is separated by comma (,), retrieve first column using
Code:
awk -F',' '{print $1}' /path/of/file.csv Code:
awk -F',' '{print $2}' /path/of/file.csv |
Thank u eklavya..
thank u.. but i want to display all columns data in the file. and in my file every column enclosed with double quotes and in that data we have a comma but i want to treat it same column. my file contain above 1 lack records.
|
If every column is separated by a double quote and a comma (",)
To retrieve first column Code:
awk -F"\"," '{print substr($1,2); }' file.csv Code:
awk -F"\"," '{print substr($2,2); }' file.csv To retrieve last column Code:
awk -F"\"," '{print substr($NF, 2, length($NF)-2)}' file.csv |
He wants to ignore commas between double quotes (third line of the sample) and doube quotes between double quotes (fourht line of the sample) for the purpose of field delimiters.
OK |
Thank u eklavya and AnanthaP
for example my file like this.
"101","ddd","sss" "102","ssa","ee" "103","dsd,ds","dsd" "104","ds"cz","dsda" i want print like this "101" "ddd" "sss" "102" "ssa" "ee" "103" "dsd,ds" "dsd" "104" "ds"cz" "dsda" pl z tell me the any command or script to display above way.. |
Code:
awk -F"\"," '{for (i=1;i<=NF;i++) print $i"\""}' file.csv |
Yes this can be done with awk. Have a look for FPAT on the manual page
|
Thank u guys..
now i have another task..
it is my file like this "101","dsds","Dasds" "102","dsdv","dsd,dsd" "103","dsdfv"ds","dfsadf" "104","dsds","dfgasd"Fvs" i want modify my file like this "101","dsds","Dasds" "102","dsdv","dsd,dsd" "103","dsdfv""ds","dfsadf" "104","dsds","dfgasd""Fvs" means in data where we have double quotes, we want to replace with 2 double quotes. |
And where is your attempt?
|
hi grail.
sample data is
"101","sds"dsd","dsf" i want modify like this "101","sds""dsd","dsf" in my file i have number of columns like this i want to modify all the columns. |
Thank u eklavya..
i am using this command:
awk -F"\"," '{for (i=1;i<=NF;i++) print $i"\""}' file.csv but it will ignore my last column data of every row. |
Firstly, please use [code][/code] tags when displaying code or data
Thank you for the sample data. Now where is your attempt to solve the problem? Others have given some suggestions, although I see the last example fails although I do not understand what you feel the error is. Using your sample data and either a script of your own or an adjustment to those presented, how have you tried to solve your new issue? |
Quote:
http://www.linuxquestions.org/questi...2/#post5262328 http://www.linuxquestions.org/questi...5/#post5262304 http://www.linuxquestions.org/questi...5/#post5262261 is going to make things not work out so well insofar as answers from the forum ... |
see your other post on this topic
http://www.linuxquestions.org/questi...63#post5262763 |
All times are GMT -5. The time now is 03:58 PM. |