Need to remove some value in CSV file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to remove some value in CSV file
# 1  
Old 03-29-2011
Need to remove some value in CSV file

Hi All

A .csv file containing multiple value on it. i need to remove some value from it. Please advise how can i find multiple value from that and remove itself. Please provide solution for this.

Thanks in advance.
# 2  
Old 03-29-2011
Posting few lines of your csv file and the desired output format would help us to help you..
# 3  
Old 03-29-2011
Hi

Below are the example value of .csv file.
Code:
"10002","UNIV OF WESTERN ONTARIO (OCUL) (#10002)","CON","I","A","","CANADA","Namer W","",""
"10003","NATIONAL CENTRAL UNIV un/pw (#10003)","CON","I","A","","TAIWAN","APAC1","",""
"10005","UNIV OF WINDSOR (OCUL) (#10005)","CON","I,K","A","","CANADA","Namer W","",""
"10006","CARLETON UNIV (OCUL) (#10006)","CON","I,SN.Q","A","","CANADA","Namer W","",""
"10009","NATIONAL TAIPEI UNIV OF TECH (#10009)","CON","I","A","","TAIWAN","APAC1","",""
"10017","YEUNGNAM UNIV (#10017)","CON","I","A","","KOREA","Lamer","",""
"10024","TIANJIN UNIV (#10024)","CON","I","A","","CHINA","APAC1","",""
"10036","UNIV OF MANITOBA (#10036)","CON","I","A","","CANADA","Namer W","",""
"10050","UNIV HEIDELBERG (#10050)","CON","A","A","","GERMANY","EUROPE PLUS","",""
"10055","DONG-EUI UNIV (#10055)","CON","I","A","","KOREA","Lamer","",""
"10056","KYUNGNAM UNIVERSITY (#10056)","CON","I","A","","KOREA","Lamer","",""
"10058","DUKE UNIV (#10058)","","I","A","NC","UNITED STATES","Namer E","",""
"10067","BEIJING JIAOTONG UNIV (NORTHERN JIAOTONG UNIV) (#10067)","CON","I, R","A","","CHINA","APAC1","",""
"10069","UNIV OF ELECTRONIC SCIENCE & TECH (#10069)","CON","I,R,K","A","","CHINA","APAC1","",""
"10074","UNIV OF BRISTOL (#10074)","CON","I","A","","UNITED KINGDOM","EUROPE PLUS","",""
"10076","SUN YAT-SEN UNIV (#10076)","CON","I","A","","CHINA","APAC1","",""
"10123","NATIONAL CHUNG CHENG UNIV (INACTIVE) (#10123)","CON","I","A","","TAIWAN","APAC1","",""
"10124","HONGIK UNIV (#10124)","CON","I","A","","KOREA","Lamer","",""
"10125","KOREA ELECTRIC POWER RESEARCH INSTITUTE - KEPRI (#10125)","CON","I","A","","KOREA","Lamer","",""
"10134","SOUTH CHINA UNIV OF TECH (#10134)","CON","I","A","","CHINA","APAC1","",""
"10135","UNIV DE CANTABRIA (#10135)","","I","A","","SPAIN","EUROPE PLUS","",""
"10146","GRIFFITH UNIV (#10146)","CON","I, K","A","","AUSTRALIA","APAC1","",""
"10158","BROWN UNIV (#10158)","","I,R","A","RI","UNITED STATES","Namer E","",""
"10165","WESTERN MICHIGAN UNIV (#10165)","","I, K","A","MI","UNITED STATES","Namer C","",""
"10167","PUKYONG UNIV1 (#10167)","CON","I","A","","KOREA","Lamer","",""

Now how can i find 10055, 10167,10024 & 10076 value from the file and remove them. Hope you understand...

Last edited by Franklin52; 03-29-2011 at 06:29 AM.. Reason: fixed code tags
# 4  
Old 03-29-2011
First sed command removes just the given numbers from the csv file preserving the remaining line content. If you want to remove the whole line containing the numbers (10055, 10167,10024 & 10076) then try second command.
Code:
sed 's/10055//g' inputfile.csv > outfile
sed '/10055/d' inputfile.csv > outfile

# 5  
Old 03-29-2011
Code:
awk -F, '$1!~/10(055|167|024|076)/' YourFile.csv

use nawk if on solaris

To have a more 'exact' matching, so that - for example - 100552 will not be matched when looking for 10055
Code:
awk -F, '$1!~/^"10(055|167|024|076)"$/' YourFile.csv


Last edited by ctsgnb; 03-29-2011 at 06:18 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove unwanted commas from a .csv file?

how to remove unwanted commas from a .csv file Input file format "Server1","server-PRI-Windows","PRI-VC01","Microsoft Windows Server 2012, (64-bit)","Powered On","1,696.12","server-GEN-SFCHT2-VMS-R013,server-GEN-SFCHT2-VMS-R031,server-GEN-SFCHT2-VMS-R023"... (5 Replies)
Discussion started by: ranjancom2000
5 Replies

2. Shell Programming and Scripting

Remove the leading and trailing date from a CSV file

I'm a newbie to shell scripting. Can anyone help with the below requirement ? The leading and trailing date of a files to be removed. 2017-07-12_gmr_tag_log_20170711.csv 2017-07-12_gmr_call_log_20170711.csv 2017-07-12_gmr_outgoing_log_20170711.csv I'm looking for output like... (7 Replies)
Discussion started by: shivamayam
7 Replies

3. Shell Programming and Scripting

How to remove space and delimit a csv file?

Hi All , I am facing a small challenge i need unix command to remove space as well as replace "|" to "," in a csv file . original file : A | B | c | D E | F | G | H I | J | K | L P | M | N | O Expected o/p: A,B,c,D E,F,G,H I,J,K,L P,M,N,O (4 Replies)
Discussion started by: Sweety532
4 Replies

4. Shell Programming and Scripting

Remove line breaks in csv file using shell script

Hi All, I've a csv file in which the record is getting break into 1 line or more than one line. I want to combine those splits into one line and remove the unwanted character existing in the record i.e. double quote symbol ("). The line gets break only when the record contains double... (4 Replies)
Discussion started by: rajak.net
4 Replies

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

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

7. Shell Programming and Scripting

How to remove line break in a csv file

Hi Experts, My requirement is to read the csv file and need to remove if any line break in it. sample data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 Row2:"Tønsberg, Brygga Kino SF",Tønsberg,202-1, Tønsberg SF 4,202-1-4 Expected data: Row1: "Oslo, Symra... (6 Replies)
Discussion started by: cnraja
6 Replies

8. Shell Programming and Scripting

How to remove Blank rows in a csv file

Hi, I need help to remove blank rows at the end of file. Sample data: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 "Tønsberg, Brygga Kino SF",Tønsberg,202-1,Tønsberg SF 4,202-1-4 ,,,, ,,,, ,,,, ,,,, Expected data: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 "Tønsberg, Brygga... (6 Replies)
Discussion started by: cnraja
6 Replies

9. Shell Programming and Scripting

Remove duplicate commas after exporting excel file to csv

Hello everyone I'm new here and this is my first post so first of all I want to say that this is a great forum and I have managed to found most of my answers in these forums : ) So with that I ask you my first question: I have an excel file which I saved as a csv. However the excel file... (3 Replies)
Discussion started by: Spunkerspawn
3 Replies

10. Shell Programming and Scripting

Remove text from a csv file using sed

I am trying to remove the ita from this file: "1234ita","john","smith" "56789ita","jim","thomas" the command i am using is: sed '/^ita/d' infile.csv > outfile.csv it is running but doing nothing, very rarely use sed so trying to learn it any help would be appreciated (2 Replies)
Discussion started by: Pablo_beezo
2 Replies
Login or Register to Ask a Question