shell-script-pt
[Top][All Lists]
Advanced

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

Re: [shell-script] filtro de conteudo de arquivo


From: Eliphas Levy Theodoro
Subject: Re: [shell-script] filtro de conteudo de arquivo
Date: Mon, 21 Jan 2002 16:29:37 -0200 (BRST)

#!/bin/sh
procura="/path/arquivo/procurado"
arquivo="seuarquivo.txt"
cab=""
while read linha; do
    [ -z "$cab" ] && cab="$linha"
    if echo "$linha" | grep -q "^$procura$"; then
        echo "$cab"
        echo "$linha"
        echo
    elif [ -z "$linha" ]; then
        cab=""
    fi
done < $arquivo

Fiz meio rapidinho mas acho que vai dar certo ':)

Fred, @ 16:00:

> Minha dúvida é a seguinte:
> Tendo um arquivo texto.
> -------
> Cabeçalho: 001
> /var/log/messages
> /var/arquivo1
> /path/arquivo/procurado
> /var/log/wtmp
>
> Cabeçalho: 002
> /usr/local/squid/etc/squid.conf
> /usr/texttwo
> /usr/alfredo/profile
> /path/arquivo/procurado
>
> Cabeçalho: 003
> /etc/shadow
> /etc/passwd
> /etc/hosts.allow
> /etc/hosts.deny
> /tmp/core
> -------
>
> Gostaria de mostrar todos os cabeçalhos, e abaixo o arquivo procurado.
> ----
> Cabeçalho: 001
> /path/arquivo/procurado
>
> Cabeçalho: 002
> /path/arquivo/procurado
>
> Cabeçalho: 003

-- 
Eliphas

Anyone sending unsolicited bulk email (UBE, SPAM) to this address will
be charged a $25 handling fee plus a $5 network traffic fee per
started kilobyte. By extracting my address from this message or its
header, you agree to these terms.
Nevertheless, spammers trying to auto-extract addresses from this
message will definitely want to include address@hidden, address@hidden,
and address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]