Skip to main content
3 of 5
corrected example. abet (without.txt) and able.txt would be created.
cas
  • 84.4k
  • 9
  • 136
  • 205

There are numerous ways to do that, including the following:

sed -e 's/$/.txt/' fileNames.txt | xargs -d '\n' touch

This assumes that there is only one filename per line in fileNames.txt. The sed script adds '.txt' to the end of each filename before piping them to xargs touch.

By using the -d '\n' option with xargs (which tells xargs to use only newline or '\n' as the delimiter rather than any whitespace) this even copes with filenames that have spaces and other potentially-problematic characters (except for \n or newline itself). e.g. if a line contained 'abet able', without -d '\n', two files (abet and able.txt) would be created. With it, only one file abet able.txt will be created.

cas
  • 84.4k
  • 9
  • 136
  • 205