[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Text processing help (sed?)



On Thu, 2003-11-13 at 15:03, BruceG wrote:
> Hey all, not a Debian specific question. I am working with some CSV files.
> Daily extracts. I was able to combine them all with cat, then yank out the
> records I needed and popped then in a smaller file using grep. Finally
> yanked duplicates using sort < file | uniq -d
> 
> Now comes the hard part. Each record begins with the date and hour. When I
> graph a month's worth of data, the graphs get nuts, so I want to remove
> specific entries from each line. Specifically, I want to replace the entry
> with a comma. A sample of the file is below:
> Date,TargetName ifIndex IfDescr,AvgIn,AvgOut,MaxIn,MaxOut
--snipped sample data--
> How would I replace 10/17/2003 1:00 with a , ?   I need to hit each day of
> the month, and I only want to show the text for 10/**/2003 0:00, 8:00,
> 16:00. The rest I want to use a , to show an empty cell.

You're right in your subject, sed is the tool to use.

sed 's/10\/17\/2003 1:00/,/' inputfilename

Or you could optionally just pipe the output of the operations creating
the output in the first place to the above without "inputfilename".

If you want to do something more detailed, I'd suggest you read up on
regular expressions and then construct your own based on what exactly
you need.

Note that in the above example I used exactly what you said. That is
REPLACED the date with a comma. So the string will have one more comma
than it did before. If you wanted to just remove the date without
actually inserting a comma, just pull the comma out of the above
command.
-- 
Alex Malinovich
Support Free Software, delete your Windows partition TODAY!
Encrypted mail preferred. You can get my public key from any of the
pgp.net keyservers. Key ID: A6D24837

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: