I want to append suffixes in a range to a string foo
located in file
. The file is guaranteed to have just one line with the string.
I have been able to do this in Bash with:
for num in {001..003}; do
echo $(cat file) $num
done
Which outputs the desired:
foo 001
foo 002
foo 003
But I was wondering if there's a better way to do it without the for loop.
I've tried things like:
$ echo $(cat file) {001..003}
foo 001 002 003
$ echo {001..003} | cat file -
foo
001 002 003
CodePudding user response:
You can use printf
in bash
:
s=$(<file)
printf "$s %s\n" {001..003}
foo 001
foo 002
foo 003
Assuming content of file
doesn't contain any printf
formatting directive.