PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > newbie question: remove lines from text-file
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

newbie question: remove lines from text-file

Réponse
 
LinkBack Outils de la discussion
Vieux 25/08/2006, 12h47   #1 (permalink)
Martin Jørgensen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut newbie question: remove lines from text-file

Hi,

I have a +200 kb log file from which I want to remove lines such as this
one:

5950K ......... ......... ......... ......... ......... ......... 59%
5600K ......... ......... ......... ......... ......... ......... 60%
5650K ......... ......... ......... ......... ......... ......... 61%

It's called wget-log. I'm not really good at linux bash shells so how do
I remove those lines with "......... ......... ......... ........." ?

I suppose I could do something like "cat wget-log |
(some-command/grep?) > newfile" but there are probably better methods,
including not creating a new file...


Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
  Réponse avec citation
Vieux 25/08/2006, 14h00   #2 (permalink)
yulangdong
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

sed -i "/......... ......... ......... ......... ......... ......... /d"
urlog

"Martin Jørgensen" <hotmail_spam@hotmail.com>
??????:1k43s3-k95.ln1@news.tdc.dk...
> Hi,
>
> I have a +200 kb log file from which I want to remove lines such as this
> one:
>
> 5950K ......... ......... ......... ......... ......... ......... 59%
> 5600K ......... ......... ......... ......... ......... ......... 60%
> 5650K ......... ......... ......... ......... ......... ......... 61%
>
> It's called wget-log. I'm not really good at linux bash shells so how do
> I remove those lines with "......... ......... ......... ........." ?
>
> I suppose I could do something like "cat wget-log |
> (some-command/grep?) > newfile" but there are probably better methods,
> including not creating a new file...
>
>
> Best regards
> Martin Jørgensen
>
> --
> --------------------------------------------------------------------------

-
> Home of Martin Jørgensen - http://www.martinjoergensen.dk



  Réponse avec citation
Vieux 25/08/2006, 14h02   #3 (permalink)
yulangdong
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

sorry,

you need escape .

"yulangdong" <yulangdong@hotmail.com> дÈëÏûÏ¢ÐÂÎÅ
:44eef415$1@news.starhub.net.sg...
> sed -i "/......... ......... ......... ......... ......... ......... /d"
> urlog
>
> "Martin Jørgensen" <hotmail_spam@hotmail.com>
> ??????:1k43s3-k95.ln1@news.tdc.dk...
> > Hi,
> >
> > I have a +200 kb log file from which I want to remove lines such as this
> > one:
> >
> > 5950K ......... ......... ......... ......... ......... ......... 59%
> > 5600K ......... ......... ......... ......... ......... ......... 60%
> > 5650K ......... ......... ......... ......... ......... ......... 61%
> >
> > It's called wget-log. I'm not really good at linux bash shells so how do
> > I remove those lines with "......... ......... ......... ........." ?
> >
> > I suppose I could do something like "cat wget-log |
> > (some-command/grep?) > newfile" but there are probably better methods,
> > including not creating a new file...
> >
> >
> > Best regards
> > Martin Jørgensen
> >
> > --

>
> --------------------------------------------------------------------------
> -
> > Home of Martin Jørgensen - http://www.martinjoergensen.dk

>
>



  Réponse avec citation
Vieux 25/08/2006, 14h14   #4 (permalink)
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

yulangdong wrote:

> "Martin Jørgensen" <hotmail_spam@hotmail.com>
> ??????:1k43s3-k95.ln1@news.tdc.dk...
>
>>Hi,
>>
>>I have a +200 kb log file from which I want to remove lines such as this
>>one:
>>
>>5950K ......... ......... ......... ......... ......... ......... 59%
>>5600K ......... ......... ......... ......... ......... ......... 60%
>>5650K ......... ......... ......... ......... ......... ......... 61%
>>
>>It's called wget-log. I'm not really good at linux bash shells so how do
>>I remove those lines with "......... ......... ......... ........." ?
>>
>>I suppose I could do something like "cat wget-log |
>>(some-command/grep?) > newfile" but there are probably better methods,
>>including not creating a new file...
>>
>>
>>Best regards
>>Martin Jørgensen
>>
>>--
>>--------------------------------------------------------------------------

>
> -
>
>>Home of Martin Jørgensen - http://www.martinjoergensen.dk

>
> sed -i "/......... ......... ......... ......... ......... ......... /d"
> urlog
>


Top-posting fixed. Please don't top-post.

A "." matches any character. Escape it ("\.") if you want to
specifically only match a period.

You also don't need to explicitly list every character if your sed
supports RE intervals, e.g. to match 6 repetitions of 9
periods-then-a-space:

sed '/\(\.\{9\} \)\{6\}/d'

Regards,

Ed.

  Réponse avec citation
Vieux 26/08/2006, 18h43   #5 (permalink)
Martin Jørgensen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

Ed Morton <morton@lsupcaemnt.com> writes:

> yulangdong wrote:
>


>> sed -i "/......... ......... ......... ......... ......... ......... /d"
>> urlog


That worked fine, thanks.

> Top-posting fixed. Please don't top-post.
>
> A "." matches any character. Escape it ("\.") if you want to
> specifically only match a period.


Only escape the first character, right? Or every one? I also don't
really understand whether or not the citation marks " " are necessary?

> You also don't need to explicitly list every character if your sed
> supports RE intervals, e.g. to match 6 repetitions of 9
> periods-then-a-space:
>
> sed '/\(\.\{9\} \)\{6\}/d'


That's too advanced for me... Can you break it up and explain that to me?


Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
  Réponse avec citation
Vieux 26/08/2006, 20h15   #6 (permalink)
First Lensman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

I would recommend learning perl and regular expressions. Try using the
following script:

Script Name: unclog.pl (or whatever you want to call it)
=======================
#!/usr/bin/perl -wn

print if (!/^.*\.{9} .*$/);

Make sure the permissions on unclog.pl are set to execute (i.e. 770)

Then run the script as follows:

unclog.pl wget-log > wget-unclog

Hope this s.

Art Ramos

Martin Jørgensen wrote:
> Hi,
>
> I have a +200 kb log file from which I want to remove lines such as this
> one:
>
> 5950K ......... ......... ......... ......... ......... ......... 59%
> 5600K ......... ......... ......... ......... ......... ......... 60%
> 5650K ......... ......... ......... ......... ......... ......... 61%
>
> It's called wget-log. I'm not really good at linux bash shells so how do
> I remove those lines with "......... ......... ......... ........." ?
>
> I suppose I could do something like "cat wget-log |
> (some-command/grep?) > newfile" but there are probably better methods,
> including not creating a new file...
>
>
> Best regards
> Martin Jørgensen
>
> --
> ---------------------------------------------------------------------------
> Home of Martin Jørgensen - http://www.martinjoergensen.dk


  Réponse avec citation
Vieux 26/08/2006, 20h43   #7 (permalink)
Xicheng Jia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

First Lensman wrote:
> I would recommend learning perl and regular expressions. Try using the
> following script:
>
> Script Name: unclog.pl (or whatever you want to call it)
> =======================
> #!/usr/bin/perl -wn
>
> print if (!/^.*\.{9} .*$/);
>
> Make sure the permissions on unclog.pl are set to execute (i.e. 770)
>
> Then run the script as follows:
>
> unclog.pl wget-log > wget-unclog
>


why not issue it directly on the command line:

perl -ne 'print if not /(??:\.){9} ){6}/' wget-log > wget-unclog

Xicheng

  Réponse avec citation
Vieux 27/08/2006, 01h05   #8 (permalink)
mik3
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file


Martin Jørgensen wrote:
> Hi,
>
> I have a +200 kb log file from which I want to remove lines such as this
> one:
>
> 5950K ......... ......... ......... ......... ......... ......... 59%
> 5600K ......... ......... ......... ......... ......... ......... 60%
> 5650K ......... ......... ......... ......... ......... ......... 61%
>
> It's called wget-log. I'm not really good at linux bash shells so how do
> I remove those lines with "......... ......... ......... ........." ?
>
> I suppose I could do something like "cat wget-log |
> (some-command/grep?) > newfile" but there are probably better methods,
> including not creating a new file...
>
>
> Best regards
> Martin Jørgensen
>
> --
> ---------------------------------------------------------------------------
> Home of Martin Jørgensen - http://www.martinjoergensen.dk



if you know Python,

o = open("newfile","a")
for lines in open("wget-log"):
if not "......... ......... ......... ........." in lines:
o.write(lines)
o.close()

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h37.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17919 seconds with 16 queries