I will explain this problem with an example. Let's say I want to create a list with two columns. Column 1 contains the file name, and column 2 contains the md5 sum of this file.
This can be done using the following script:
for FILE in `ls -p | grep -v "/"`; do printf "%s %s\n" "$FILE" `md5 -q "$FILE"`; done;
Is it possible to do this on a single line using pipes? I tried using different combinations of sed , xargs and printf , but I think I'm missing something. Here is one of my attempts:
ls -p | grep -v "/" | xargs -I FILE printf "%s %s\n" FILE `md5 -q FILE`
In this attempt, the FILE inside the reverse steps is not replaced, which is not surprising.
Is this where I should just use a multi-line script? Since there is no logic or control flow, I feel that a single liner should be possible and that maybe I am not using my tools properly, or I have not found a suitable tool.
Apologies for the title, I have no idea what to call this question.
source share