齐天大圣
齐天大圣

Reputation: 1189

bash script: how to display output in different line

i'm trying use one line of code to solve a problem

echo $(find . -maxdepth 1 -type f -newer $1  | sed 's,\.\/,,g')

this will print out all the file in current folder that are newer than the input file. But it prints out in one single line:

file1 file2 file3 file4....

how can i display each file name in a single line like:

file1
file2
file3
...

This seems to be a very simple but i've been searching and have no solution. Thank you in advance.

Upvotes: 3

Views: 1126

Answers (2)

Aman
Aman

Reputation: 1197

pipe it to tr:

... | tr " " "\n"

Upvotes: 0

John Kugelman
John Kugelman

Reputation: 361585

Get rid of the echo and the $(...).

find . -maxdepth 1 -type f -newer "$1" | sed 's,\.\/,,g'

If you have GNU find you can replace the sed with a -printf action:

find . -maxdepth 1 -type f -newer "$1" -printf '%P\n'

Upvotes: 6

Related Questions