Re:GNU Coreutils Gotchas
by ksherlock on Monday November 30, 2015 @09:05AM
(#10649382)
if you need to pipe it in, you should
[ Parent
| on HN ]
uhm, what?
Can you give an example where I have a file (a.txt) of 100 file names and need the basename of each? I'm pretty sure dvh just used echo to show a simple example, not an actual use.
Re:GNU Coreutils Gotchas
by erdbeerkaese on Monday November 30, 2015 @09:55AM
(#10649661)
Another way:
while read line ; do basename "$line" ; done < a.txtYeah, I think I prefer yours. Probably more robust wrt filenames-with-whitespace too.
Both solutions although nice and helpful pretty much illustrate why I ended up writing a filter capable version.
How about this?
for f in $(cat a.txt); do basename "$f"; done1. Broken by filenames that contain whitespace.
2. The shell will expand * and ? (maybe others) in the filenames
xargs basename -a < a.txt