zsh-users
 help / color / mirror / code / Atom feed
* Somehow smoking a pipe twice...?
@ 2012-09-30 12:27 meino.cramer
  2012-09-30 12:52 ` Keith Bawden
  2012-09-30 16:16 ` Bart Schaefer
  0 siblings, 2 replies; 3+ messages in thread
From: meino.cramer @ 2012-09-30 12:27 UTC (permalink / raw)
  To: zsh-users

Hi,

Is this possible somehow with zsh?

My first command runs inside my mailfolder and looks like this

    ls -l `grep -l kolkrabe *`

which give me a list of all files which contains the word "Kolkrabe"
("Kolkrabe" is german for "common raven". Latin "Corvus corax").

But additionally I want to know the contents of the line, which 
matches the grep command added to the end of the line "ls -l"
shows for each file. That is the output of

    grep -i "Kolkrabe" *

How can I combine both to one command ?

Thank you very much for any help in advance!
Best regards,
mcc




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Somehow smoking a pipe twice...?
  2012-09-30 12:27 Somehow smoking a pipe twice...? meino.cramer
@ 2012-09-30 12:52 ` Keith Bawden
  2012-09-30 16:16 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Keith Bawden @ 2012-09-30 12:52 UTC (permalink / raw)
  To: meino.cramer; +Cc: zsh-users

On Sun, Sep 30, 2012 at 9:27 PM,  <meino.cramer@gmx.de> wrote:
> Is this possible somehow with zsh?

I may be misunderstanding your question but this is possible with grep alone.

> My first command runs inside my mailfolder and looks like this
>
>     ls -l `grep -l kolkrabe *`
>

# SNIP

>
>     grep -i "Kolkrabe" *
>
> How can I combine both to one command ?
>

grep -irH "Kolkrabe" ./

This will perform a recursive case insensitive search from ./ and will
return the filename (-H is default on some versions of grep) and will
append the line that matches.

Regards, Keith


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Somehow smoking a pipe twice...?
  2012-09-30 12:27 Somehow smoking a pipe twice...? meino.cramer
  2012-09-30 12:52 ` Keith Bawden
@ 2012-09-30 16:16 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2012-09-30 16:16 UTC (permalink / raw)
  To: zsh-users

On Sep 30,  2:27pm, meino.cramer@gmx.de wrote:
}
} My first command runs inside my mailfolder and looks like this
} 
}     ls -l `grep -l kolkrabe *`
} 
} which give me a list of all files which contains the word "Kolkrabe"
} ("Kolkrabe" is german for "common raven". Latin "Corvus corax").
} 
} But additionally I want to know the contents of the line, which 
} matches the grep command added to the end of the line "ls -l"
} shows for each file.

Keith has it at least partly right here.  You need to let grep print
both the file name and the line contents.  At that point though, if
you want the "ls" output as well, you'll have to capture the grep
output and substitute in the "ls" output.

You can do this with something like:

    temp==(grep kolkrabe *) eval \
      'paste =(ls -l $(cut -d : -f 1 $temp)) =(cut -d : -f 2 $temp)'

But the only zsh-ish thing about that is the use of =(...) to manage
the temporary files for you.  "paste" also takes a -d option if you
want something other than a tab character between the ls output and
the grep output.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-09-30 16:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-30 12:27 Somehow smoking a pipe twice...? meino.cramer
2012-09-30 12:52 ` Keith Bawden
2012-09-30 16:16 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).