cookya
cookya

Reputation: 3307

viewing file's content for each file-name appearing in a list

I'm creating a list of file-names using the command:

ls | grep "\.txt$"

I'm getting a list of files:

F1.txt
F2.txt
F3.txt
F4.txt

I want to view the content of these files (using less / more / cat /...)

is there a way to do this by pipping?

(Btw, I got a list of file-names using a more complex command, this is just a simpler example for clarification)

Upvotes: 0

Views: 81

Answers (3)

Nykakin
Nykakin

Reputation: 8747

What about:

cat $(ls | grep "\.txt$")

Upvotes: 1

miku
miku

Reputation: 188114

Would this be enough?

$ cat *txt

For richer queries, you could use find and xargs:

$ find . -name "*txt" | xargs cat

Upvotes: 1

Thava
Thava

Reputation: 1665

you can try something like this:

#!/bin/bash

for i in *.txt
do
  echo Displaying file $i ...
  more  $i
done

Upvotes: 1

Related Questions