Everything that grep
does can be done within sed
: see this tutorial. In this case you add -e '/PATTERN/d'
to reproduce the grep -v
option:
ls | sed -E -e '/_init_/d' -e 's/^([a-zA-Z0-1]+)/import \1/' >> __init__.py
You can eliminate ls
by using instead:
for f in *; do echo "$f"; done | sed -E -e '/_init_/s' -e 's/^([a-zA-Z0-1]+)/import \1/' >> __init__.py
This removes the need for using an external program and handling any extra information or flags that may be added by ls
defaults.
There are several ways to add the files in reverse order:
- If you use
ls
, then ls -r
will output the files in reverse order.
- If you use
for f in *; ...
, then pipe the output through sort -r
.
- You can use
tac
to reverse the line order in the output afterwards.
- The long-winded way is to output each file to a single-line file, append the current output list to it, then move this to overwrite the running output list.
ls(1)
. :)