0

I want to generate a text file with the list of files present in the folder

ls | xargs echo > text.txt

I want to prepend the IP address to each file so that I can run parallel wget as per this post : Parallel wget in Bash

So my text.txt file content will have these lines :

123.123.123.123/file1
123.123.123.123/file2
123.123.123.123/file3

How can I append a string as the ls feeds xargs? (and also add line break at the end.) Thank you

Community
  • 1
  • 1
Yvon Huynh
  • 453
  • 3
  • 16

1 Answers1

1

Simply printf and globbing to get the filenames:

printf '123.123.123.123/%s\n' * >file.txt

Or longer approach, leverage a for construct with help from globbing:

for f in *; do echo "123.123.123.123/$f"; done >file.txt

Assuming no filename with newline exists.

heemayl
  • 39,294
  • 7
  • 70
  • 76