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
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
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
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
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
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
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
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
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
Vieux 27/08/2006, 22h22   #9
Janis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

Martin Jørgensen wrote:
> Ed Morton <morton@lsupcaemnt.com> writes:
>
> > sed '/\(\.\{9\} \)\{6\}/d'

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


It's easier to understand if you temporarily remove the - necessary -
backslashes...

/ start of regexp
( start of grouping
\.{9} a literal dot (needs escaping), nine times
) a space, and end of grouping
{6} six times the whole group
/d end of regexp, and delete command

Now every bracket for ranges and grouping requires escaping with a
backslash.

Janis

  Réponse avec citation
Vieux 28/08/2006, 15h02   #10
Martin Jørgensen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

"Janis" <janis_papanagnou@hotmail.com> writes:

> Martin Jørgensen wrote:
>> Ed Morton <morton@lsupcaemnt.com> writes:
>>
>> > sed '/\(\.\{9\} \)\{6\}/d'

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

>
> It's easier to understand if you temporarily remove the - necessary -
> backslashes...
>
> / start of regexp
> ( start of grouping
> \.{9} a literal dot (needs escaping), nine times
> ) a space, and end of grouping
> {6} six times the whole group
> /d end of regexp, and delete command
>
> Now every bracket for ranges and grouping requires escaping with a
> backslash.


hmm. Thanks. I think I'll have to see that a couple of more times or
even try to experiment with it before I clearly understand it...


Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
  Réponse avec citation
Vieux 28/08/2006, 23h58   #11
Janis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

Martin Jørgensen wrote:
> "Janis" <janis_papanagnou@hotmail.com> writes:
>
> > Martin Jørgensen wrote:
> >> Ed Morton <morton@lsupcaemnt.com> writes:
> >>
> >> > sed '/\(\.\{9\} \)\{6\}/d'
> >>
> >> That's too advanced for me... Can you break it up and explain that to me?

> >
> > It's easier to understand if you temporarily remove the - necessary -
> > backslashes...
> >
> > / start of regexp
> > ( start of grouping
> > \.{9} a literal dot (needs escaping), nine times
> > ) a space, and end of grouping
> > {6} six times the whole group
> > /d end of regexp, and delete command
> >
> > Now every bracket for ranges and grouping requires escaping with a
> > backslash.

>
> hmm. Thanks. I think I'll have to see that a couple of more times or
> even try to experiment with it before I clearly understand it...


Regexps are not easy to read, especially if you're not used to.
I don't know where you have concrete problems, so I'll guess...

The input text to be matched by the pattern contains only dots
'.' and spaces ' '. To avoid repetition of such regexp atoms you
may want to use friendly counting schemes. In many advanced
regexp syntaxes it is possible to define ranges like

{2,5} at least two times, at most 5 times
{,5} at most five times, no lower limit
{2,} at least 2 times, no upper limit
{2} exactly two times

These ranges apply to the preceeding regexp atom, so

\.{2} means exactly two times the dot
..{2} means exactly two times any character

If you have more than a single atom to be repeated you may use
brackets to group a group of atoms

(whatever){5} repeat the pattern within the brackets 5 times

The brackets (, ), {, }, are meta characters in the regexp syntax,
and some regexp parsers require them to be escaped by a backslash
e.g. to distinguish them from the literal bracket symbols.

Janis


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


  Réponse avec citation
Vieux 29/08/2006, 19h51   #12
Martin Jørgensen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

"Janis" <janis_papanagnou@hotmail.com> writes:

> Martin Jørgensen wrote:
>> "Janis" <janis_papanagnou@hotmail.com> writes:
>>
>> > Martin Jørgensen wrote:
>> >> Ed Morton <morton@lsupcaemnt.com> writes:
>> >>
>> >> > sed '/\(\.\{9\} \)\{6\}/d'
>> >>
>> >> That's too advanced for me... Can you break it up and explain that to me?
>> >
>> > It's easier to understand if you temporarily remove the - necessary -
>> > backslashes...
>> >
>> > / start of regexp
>> > ( start of grouping
>> > \.{9} a literal dot (needs escaping), nine times
>> > ) a space, and end of grouping
>> > {6} six times the whole group
>> > /d end of regexp, and delete command
>> >
>> > Now every bracket for ranges and grouping requires escaping with a
>> > backslash.

>>
>> hmm. Thanks. I think I'll have to see that a couple of more times or
>> even try to experiment with it before I clearly understand it...

>
> Regexps are not easy to read, especially if you're not used to.
> I don't know where you have concrete problems, so I'll guess...


I have problems reading it all over the place, everywhere :-)

> The input text to be matched by the pattern contains only dots
> '.' and spaces ' '. To avoid repetition of such regexp atoms you
> may want to use friendly counting schemes. In many advanced
> regexp syntaxes it is possible to define ranges like
>
> {2,5} at least two times, at most 5 times
> {,5} at most five times, no lower limit
> {2,} at least 2 times, no upper limit
> {2} exactly two times


Thanks.

> These ranges apply to the preceeding regexp atom, so
>
> \.{2} means exactly two times the dot
> .{2} means exactly two times any character


How about \.\{2\} ?

> If you have more than a single atom to be repeated you may use
> brackets to group a group of atoms
>
> (whatever){5} repeat the pattern within the brackets 5 times


Ok.

> The brackets (, ), {, }, are meta characters in the regexp syntax,
> and some regexp parsers require them to be escaped by a backslash
> e.g. to distinguish them from the literal bracket symbols.


Oh... What's the name of my regexp parser if I type sed '/\(\.\{9\}
\)\{6\}/d' in bash or a script?


Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
  Réponse avec citation
Vieux 30/08/2006, 07h57   #13
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

On 2006-08-29, Martin Jørgensen wrote:
>
> Oh... What's the name of my regexp parser if I type sed '/\(\.\{9\}
> \)\{6\}/d' in bash or a script?


sed

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 30/08/2006, 18h45   #14
Martin Jørgensen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

"Chris F.A. Johnson" <cfajohnson@gmail.com> writes:

> On 2006-08-29, Martin Jørgensen wrote:
>>
>> Oh... What's the name of my regexp parser if I type sed '/\(\.\{9\}
>> \)\{6\}/d' in bash or a script?

>
> sed


Is awk also a regexp parser? Is the shell? Like bash?


Best regards
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
  Réponse avec citation
Vieux 30/08/2006, 22h21   #15
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

On 2006-08-30, Martin Jørgensen wrote:
> "Chris F.A. Johnson" <cfajohnson@gmail.com> writes:
>
>> On 2006-08-29, Martin Jørgensen wrote:
>>>
>>> Oh... What's the name of my regexp parser if I type sed '/\(\.\{9\}
>>> \)\{6\}/d' in bash or a script?

>>
>> sed

>
> Is awk also a regexp parser?


Yes.

> Is the shell? Like bash?


Bash can use regular expressions in the non-portable [[ ... ]]
syntax. See the man page for more info.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 30/08/2006, 22h36   #16
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question: remove lines from text-file

2006-08-30, 17:21(-04), Chris F.A. Johnson:
> On 2006-08-30, Martin Jørgensen wrote:
>> "Chris F.A. Johnson" <cfajohnson@gmail.com> writes:
>>
>>> On 2006-08-29, Martin Jørgensen wrote:
>>>>
>>>> Oh... What's the name of my regexp parser if I type sed '/\(\.\{9\}
>>>> \)\{6\}/d' in bash or a script?
>>>
>>> sed

>>
>> Is awk also a regexp parser?

>
> Yes.
>
>> Is the shell? Like bash?

>
> Bash can use regular expressions in the non-portable [[ ... ]]
> syntax. See the man page for more info.


(only recent (>3) versions, and that's some sort of GNU regexps).

And every (well most) shell has expr, sed, perl, grep or awk
though generally not builtin (but what would be the point?)

zsh (Perl compatible RE) and ksh93 (AT&T RE) also have internal
support for regular expressions.

--
Stéphane
  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 05h19.


Édité par : vBulletin® version 3.7.3
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 ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,22764 seconds with 24 queries