|
|
How to pipe in an input list of files to awk
Hi,
I have a bunch of a files in a directory. Is there a simple one line
command (without using foreach)
to run awk on all files in the directory?
(Say I want to print th efifth line of all files in the directory). I
tried something like
awk 'NR ==5' < (ls *)
any variants of the above, but it did not work. any idea on how this
can be done?
Thanks
|
|
0
|
|
|
|
Reply
|
Melroy
|
3/16/2009 6:12:25 AM |
|
On Mar 16, 2:12=A0pm, Melroy <melroysoa...@hotmail.com> wrote:
> Hi,
> I have a bunch of a files in =A0a directory. Is there a simple one line
> command (without using foreach)
> to run awk on all files in the directory?
> (Say I want to print th efifth line of all files in the directory). I
> tried something like
> awk 'NR =3D=3D5' < (ls *)
Maybe you should use
awk 'FNR =3D=3D 5' *
> any variants of the above, but it did not work. any idea on how this
> can be done?
> Thanks
|
|
0
|
|
|
|
Reply
|
hpt
|
3/16/2009 8:07:36 AM
|
|
On Sun, 15 Mar 2009 23:12:25 -0700, Melroy wrote:
> Hi,
> I have a bunch of a files in a directory. Is there a simple one line
> command (without using foreach)
> to run awk on all files in the directory? (Say I want to print th efifth
> line of all files in the directory). I tried something like
> awk 'NR ==5' < (ls *)
> any variants of the above, but it did not work. any idea on how this can
> be done?
> Thanks
Aside from the fact that NR == 5 will only work with the first file, the
easy way is
awk 'FNR==5' *
--
T.E.D. (tdavis@mst.edu)
|
|
0
|
|
|
|
Reply
|
Ted
|
3/16/2009 12:45:31 PM
|
|
On Mar 16, 7:12=A0am, Melroy <melroysoa...@hotmail.com> wrote:
> Hi,
> I have a bunch of a files in =A0a directory. Is there a simple one line
> command (without using foreach)
> to run awk on all files in the directory?
> (Say I want to print th efifth line of all files in the directory). I
> tried something like
> awk 'NR =3D=3D5' < (ls *)
> any variants of the above, but it did not work. any idea on how this
> can be done?
> Thanks
If the directory doesn't have other directories
cat * | awk 'NR =3D=3D 5'
Probably you can play with the find(1) command also
|
|
0
|
|
|
|
Reply
|
pmarin
|
3/16/2009 2:05:52 PM
|
|
Le Mon, 16 Mar 2009 07:05:52 -0700 (PDT),
pmarin a =C3=A9crit :
> On Mar 16, 7:12=C2=A0am, Melroy <melroysoa...@hotmail.com> wrote:
> > I have a bunch of a files in =C2=A0a directory. Is there a simple one
> > line command (without using foreach)
> > to run awk on all files in the directory?
> > (Say I want to print th efifth line of all files in the directory).
> > I tried something like
> > awk 'NR =3D=3D5' < (ls *)
> > any variants of the above, but it did not work. any idea on how this
> > can be done?
> > Thanks
>=20
> If the directory doesn't have other directories
> cat * | awk 'NR =3D=3D 5'
No, with this command you concatenate all files then
extract the fifth line.
Simply use as said by others
awk 'FNR=3D=3D5' *
> Probably you can play with the find(1) command also
Yes, with find you can using something like
find ./ -maxdepth 1 -type f -exec awk 'NR=3D=3D5' {} \;
for files in current directory only, of course.
--=20
Jacques.
|
|
0
|
|
|
|
Reply
|
Kojak
|
3/16/2009 4:14:28 PM
|
|
|
4 Replies
454 Views
(page loaded in 0.092 seconds)
|
|
|
|
|
|
|
|
|