Mombu the GNU Linux Forum sponsored links

Go Back   Mombu the GNU Linux Forum > GNU_Linux > Text processing help (sed?)
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 24th April 22:17
bruceg
External User
 
Posts: 1
Default Text processing help (sed?)



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

10/17/2003 0:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.12,0.04,0.18,0.05

10/17/2003 1:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.24,0.09,0.26,0.16

10/17/2003 2:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.22,0.09,0.33,0.12

10/17/2003 3:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.08,0.05,0.11,0.06

10/17/2003 4:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.16,0.05,0.23,0.08

10/17/2003 5:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.18,0.07,0.31,0.08

10/17/2003 6:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.58,0.07,0.94,0.09

10/17/2003 7:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),1.32,0.05,1.57,0.06

10/17/2003 8:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),2.11,0.03,2.76,0.04

10/17/2003 9:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),2.44,0.05,3.36,0.05

10/17/2003 10:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),2.15,0.03,2.4,0.04

10/17/2003 11:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),1.97,0.04,2.07,0.04

10/17/2003 12:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),1.73,0.04,2.02,0.04

10/17/2003 13:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),2.09,0.05,2.88,0.08

10/17/2003 14:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),2.03,0.04,2.69,0.05

10/17/2003 15:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),1.53,0.04,1.72,0.04

10/17/2003 16:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),2.64,0.04,3.98,0.06

10/17/2003 17:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),2.04,0.06,2.69,0.07

10/17/2003 18:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.82,0.12,1.16,0.22

10/17/2003 19:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.2,0.05,0.28,0.08

10/17/2003 20:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.03,0.03,0.06,0.03

10/17/2003 21:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.07,0.47,0.08,0.75

10/17/2003 22:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.05,0.03,0.08,0.05

10/17/2003 23:00,10.2.1.101 127 10/100 utp ethernet (cat
3/5),0.03,0.03,0.05,0.05

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.


--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Reply With Quote


  sponsored links


2 25th April 08:44
ashish
External User
 
Posts: 1
Default Text processing help (sed?)



Not clear what you want, I am guessing you want to remove the date and time
leaving behind just a comma.

Just one of the many ways...
| sed 's/[^,]*//'

If you want to keep the date and time for the first entry(line), but strip off
all the remaining date and times, then...
| sed '2,$s/[^,]*//'


Cheers,
Ashish.


--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Reply With Quote
3 25th April 19:36
alex malinovich
External User
 
Posts: 1
Default Text processing help (sed?)


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


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQA/tImVBPYwh6bSSDcRAr9GAJ9f2M79QyQnrh/OqUEaVW3n+yRHowCfR+uP
TM7o6Fm8QKTAaTKemnaHcSY=
=qY2J
-----END PGP SIGNATURE-----
  Reply With Quote
4 26th April 05:29
jfahnenmueller
External User
 
Posts: 1
Default Text processing help (sed?)


Hi Bruce,

awk is a quite powerful tool for that sort of thing.

Its basic structure is
/pattern/ {action}
i. e. it reads a line from the input file and if the line matches /pattern/ it
does {action} (e. g. write the line to output or write "," instead).

It is described very well in the manpage.


HTH
--
Joachim Fahnenmüller

# Hi! I'm a .signature virus. Copy me into
# your ~/.signature to help me spread!


--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Reply With Quote
5 26th April 05:29
bruceg
External User
 
Posts: 1
Default Text processing help (sed?)


----- Original Message -----
From: "Joachim Fahnenmueller" <JFahnenmueller@t-online.de>
To: "Debian-User" <debian-user@lists.debian.org>
Sent: Friday, November 14, 2003 11:42 AM
Subject: Re: Text processing help (sed?)

/pattern/ it


Thanks Joachim - I'll check out the manpage.


--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666