Skip to main content
added 79 characters in body
Source Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

There are numerous ways to do that, including the following (assuming GNU xargs):

sed -e '/^[^[[:space:]*$]]*$/d' -e 's/$/.txt/' fileNames.txt | xargs -drd '\n' touch --

This assumes that there is only one filename per line in fileNames.txt. The sed script deletes blank lines (thanks to @rubynorails) and adds '.txt' to the end of each filename before piping them to xargs touch.

By using the -d '\n' option with xargs (whicha GNU extension, which tells xargsxargs to use only newline or '\n' as the delimiter rather than any whitespace, and disables quote processing) 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.

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

sed -e '/^[:space:]*$/d' -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 deletes blank lines (thanks to @rubynorails) and 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.

There are numerous ways to do that, including the following (assuming GNU xargs):

sed -e '/^[[:space:]]*$/d' -e 's/$/.txt/' fileNames.txt | xargs -rd '\n' touch --

This assumes that there is only one filename per line in fileNames.txt. The sed script deletes blank lines (thanks to @rubynorails) and adds '.txt' to the end of each filename before piping them to xargs touch.

By using the -d '\n' option with xargs (a GNU extension, which tells xargs to use only newline or '\n' as the delimiter rather than any whitespace, and disables quote processing) 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.

@rubynorails idea of removing blank lines was good - added it here
Source Link
cas
  • 84.4k
  • 9
  • 136
  • 205

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

sed -e '/^[:space:]*$/d' -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 deletes blank lines (thanks to @rubynorails) and 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.

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.

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

sed -e '/^[:space:]*$/d' -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 deletes blank lines (thanks to @rubynorails) and 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.

corrected example. abet (without.txt) and able.txt would be created.
Source Link
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.txt and able.txt) would be created. With it, only one file abet able.txt will be created.

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.txt and able.txt) would be created. With it, only one file abet able.txt will be created.

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.

added 159 characters in body
Source Link
cas
  • 84.4k
  • 9
  • 136
  • 205
Loading
Source Link
cas
  • 84.4k
  • 9
  • 136
  • 205
Loading