Shellscriptbeginner
Shellscriptbeginner

Reputation: 917

shell script filter question

I am trying to store the resulting list from "ls -la" into a variable then filter out some files name, after that print out only the filtered file names (along with the date and stuff like how ls -la does it" again, but when I do that everything is in one line, is there a way to make sure every file name are on different lines?

thanks in advance

Upvotes: 0

Views: 521

Answers (3)

ghostdog74
ghostdog74

Reputation: 342293

if you want to filter file names, eg , don't list all txt files

shopt -s extglob
ls !(*.txt)

Upvotes: 4

chinmaya
chinmaya

Reputation: 609

ls -al | grep -v "file-pattern-you-want-to-filter-out"

Upvotes: 1

Brian Campbell
Brian Campbell

Reputation: 332756

Use a pipe instead of storing it in a variable.

ls -la | filter

Where filter is whatever you're using to filter.

That's about as good an answer as I can give unless you can provide some more details on exactly what you're trying to do.

Upvotes: 4

Related Questions