John Smith
John Smith

Reputation: 115

How to cat all files with filename with certain words in unix

I have a bunch of file in one directory, what I wanted to do is:

cat a-12-08.json b-12-08_others.json b-12-08-mian.json >> new.json

But there are too many files, is there any command I can use to cat all files with "12-08" in their filename?

I found the solution below.

Upvotes: 0

Views: 4146

Answers (3)

c4f4t0r
c4f4t0r

Reputation: 1641

you can use find to do what you want to archive:

find . -type f -name '*12-08*' -exec sh -c 'grep "one" {} && cat {} >> /tmp/output.txt' \;

In this way you can cat the files with contain the word that you looking for

Upvotes: 1

Barmar
Barmar

Reputation: 781096

Use a wildcard name:

cat *12-08* >>new.json

This will work as long as there aren't so many files that you exceed the maximum length of a command line, ARG_MAX (2MB on the Linux systems I checked).

Upvotes: 0

John Smith
John Smith

Reputation: 115

Here is the answer:

cat *12-08* >> new.json

Upvotes: 2

Related Questions