I'm trying to create a macro for OS X:
- Paste the text "Latest file:" and paste the name of the newest file.
One of its options is "execution of a shell script", so I thought it would be for 1. After Googling around a while I came up with this:
cd / path / from / directory / ls-tt | Head-n1
This is OK, and returns the first filename. However, it also includes a line break, which I do not want as 2: I can output the "latest file:" text with a different action in the app, and paste the file name behind it . But I'm thinking that you can not return the result of "random text" + ls
command.
So my question is this: do I command it only ls
? And how can I get the name of the latest file just without any line breaks?
Since you are already using pipes, simply enter another place there:
ls -t | Head-n1 | Awk '{printf ("latest file:% s", $ 0)}'
(Note that "printf" does not include '\ n' at the end
< P> Edit:With Arkku's suggestion to exit awk after the first line, it looks like:
ls -t | awk '{printf ("Latest file:% s", $ 0), exit} '
Comments
Post a Comment