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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing strings in a log file and saves as a new csv
# 1  
Old 12-16-2008
Computer 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 Smilie. 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

my-test1/lab_mt01.tst,lab_mt01.tst,ge-3/3/1.140
my-test2/lab_mt02.tst,lab_mt02.tst,lo0.140

2) I need a method to read this file, line by line, ignoring the first statement until it reaches the first slash, then from there, replaces the commas with semicolons, so it'll look like this

from
my-test1/lab_mt01.tst,lab_mt01.tst,ge-3/3/1.140
my-test2/lab_mt02.tst,lab_mt02.tst,lo0.140

to
lab_mt01.tst;lab_mt01.tst;ge-3/3/1.140
lab_mt02.tst;lab_mt02.tst;lo0.140

and saves it in csv format.

That would help for now. I really appreaciate your help. Im very new in shell/perl so I would hope an answer which suits the really2 'dummies' :P.

Thank you!.
# 2  
Old 12-16-2008
to simply recplace all ',' characters with ';', you can use sed:
Code:
sed 's/,/;/g' < inputfile.log > outputfile.csv

To throw away everything up to the first slash, you can use sed again:
Code:
sed 's/^[^\/]*\///'

So that gives:
Code:
sed 's/^[^\/]*\///' < inputfile.log | sed 's/,/;/g' > outputfile.csv

But don't forget that this isn't much of a csv anymore without any commas to seperate things...
# 3  
Old 12-17-2008
Thanks I'll update
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 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 :... (5 Replies)
Discussion started by: msafwan82
5 Replies

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

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