'pipe output of ls to echo to append prefix to list
I am trying to pipe data to split in a bash script. I have a directory that consists of
a.txt
b.txt
c.txt
...
I would like to make a summary file that lists these files in batches of a thousand. The following gets me close
ls *.txt | sort | split -l 1000
My problem is I want it to look like
file a.txt
file b.txt
etc...
my plan was to add an echo file ???? in there to make that happen but I cannot pipe ls to echo
Any ideas
Solution 1:[1]
Don't parse the result of ls, you might better do something like this:
find ./ -maxdepth 1 -name "*.txt" -exec echo "file" {} \; | sort
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dominique |
