Replacing strings in csv file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing strings in csv file.
# 1  
Old 02-27-2009
Replacing strings in csv file.

Hi, I have a problem..

1) I have a file that contains the lines as below :

VRF-TM_DummyLab/mse02.lab,mse02.lab,ge-2/0/7.222
VRF-EMS_HUAWEI_MSAN_208/mse01.lab,mse01.lab,xe-1/0/0.208

2) I need a method to read this file, line by line

from :
VRF-TM_DummyLab/mse02.lab,mse02.lab,ge-2/0/7.222
VRF-EMS_HUAWEI_MSAN_208/mse01.lab,mse01.lab,xe-1/0/0.208

to :
VRF-TM_DummyLab/mse02.lab,ge-2/0/7.222
VRF-EMS_HUAWEI_MSAN_208/mse01.lab,xe-1/0/0.208

removing the text highlighted in red!

and save it in csv file

The would help for now. I really appreciate your help.

Thank you!
# 2  
Old 02-27-2009
Code:
$ cat file
VRF-TM_DummyLab/mse02.lab,mse02.lab,ge-2/0/7.222
VRF-EMS_HUAWEI_MSAN_208/mse01.lab,mse01.lab,xe-1/0/0.208
$ cat file  | sed 's/mse0[12]\.lab,//'
VRF-TM_DummyLab/mse02.lab,ge-2/0/7.222
VRF-EMS_HUAWEI_MSAN_208/mse01.lab,xe-1/0/0.208
$

# 3  
Old 02-27-2009
Thanks you very much! Smilie
The text in red can be variant. Is that possible to use the command to remove text that beginning after slash & ending at first comma?

Last edited by msafwan82; 02-27-2009 at 06:33 AM..
# 4  
Old 02-27-2009
Code:
$ cat VRF
VRF-TM_DummyLab/mse02.lab,mse02.lab,ge-2/0/7.222
VRF-EMS_HUAWEI_MSAN_208/mse01.lab,mse01.lab,xe-1/0/0.208

$ sed 's/\/.[a-zA-Z0-9]*\.[a-zA-Z0-9]*,/\//' VRF
VRF-TM_DummyLab/mse02.lab,ge-2/0/7.222
VRF-EMS_HUAWEI_MSAN_208/mse01.lab,xe-1/0/0.208

cheers!!
# 5  
Old 02-27-2009
assuming the text to be replaced would be [alphanumeric].[alphanumeric]
# 6  
Old 03-01-2009
U help me a lots! Thank you.. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

2. Shell Programming and Scripting

Finding/replacing strings in some files based on a file

Hi, We have a file (e.g. a .csv file, but could be any other format), with 2 columns: the old value and the new value. We need to modify all the files within the current directory (including subdirectories), so find and replace the contents found in the first column within the file, with the... (9 Replies)
Discussion started by: Talkabout
9 Replies

3. UNIX for Advanced & Expert Users

Replacing the comma in .csv file in unix

Hi All, Could some one help me on one of my requirement below: I have a sequential file with 4fields in it and it is a comma (,) seperated file. Delimeter is 'comma'. But in of the file column for ex: 3rd column it is 'Description' (column name) I am getting the values with commas.... (6 Replies)
Discussion started by: eskay_s
6 Replies

4. Shell Programming and Scripting

Replacing Strings in a File

I have a input file which looks like this: Value1="" Value2="" Value3="" ListOfValues=" $Value1 $Value2 $Value3" I have another program which computes the values ($val1, $val2, $val3). So if $val1 is 'A', $val2 is 'B' and $val3 is 'C', I should edit the input file so it will look like:... (6 Replies)
Discussion started by: laiko
6 Replies

5. Shell Programming and Scripting

Replacing Strings in a File

I have a input file which looks like this: Value1="" Value2="" Value3="" ListOfValues=" $Value1 $Value2 $Value3" I have another program which computes the values ($val1, $val2, $val3). So if $val1 is 'A', $val2 is 'B' and $val3 is 'C', I should edit the input file so it will look like:... (0 Replies)
Discussion started by: laiko
0 Replies

6. Shell Programming and Scripting

Replacing text in a .csv file using Perl

I have played with this for some time but i dont seem like i am getting it right. I am trying to change the delimiters on a file so i can import it into a database. this file has rows of data separated by enter Right now the delimiters are represented by tabs and " ". e.g. "dlfkldfs... (9 Replies)
Discussion started by: salemh
9 Replies

7. Shell Programming and Scripting

Replacing strings in a log file and saves as a new csv

Hello Im new here.I need to replace strings and change it into csv format, or at least saves the file as csv if that would work :p. Heres an example of my scenario 1) I have a log file, named abc.log, and its like a txt based file anyway, and the content looks like this ... (2 Replies)
Discussion started by: tententen
2 Replies

8. UNIX for Dummies Questions & Answers

Replacing characters in csv file

Hello all, This is my first post here, so please excuse me if this question is too obvious or has been asked before. I am new to Unix and although I tried to search your forum for the answer to my question, I could not find an answer that would help me. I have a 500MB csv file with numeric values... (1 Reply)
Discussion started by: finwhiz
1 Replies

9. Shell Programming and Scripting

replacing strings with text from other file

Hi, Im trying to update some properties files with text from another file: file1 user=xyz file2 user= after script file2 user=xyz Im using this reading the $QUARTZURL,ETC... from quartz.properties: echo... (1 Reply)
Discussion started by: mc1392
1 Replies

10. Shell Programming and Scripting

replacing commas with tilde in csv file.

hello all, i have a comma delimited file. i want to replace the commas in the file with the tilde symbol using sed. how can i do this? thanks. (4 Replies)
Discussion started by: femig
4 Replies
Login or Register to Ask a Question