Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • Hey this works great! i just want to ask if you can incorporate two more things into the command. 1. if there is some text before file.txt can the command still look for those files? will it combine them or will they be separate? and 2. when moving the files to the destination directory, is there a way to concatenate files if the exact file name exists? lastly, if i want it to just find .txt files without specifying a name is there a way to do that? Commented Feb 28, 2023 at 17:57
  • 1. Yes, just use '*file*.txt', I just don't understand the "combine" question. Each input filename should have one output filename (unless there are input files with underscores). 2. Why? Each file should already have one destination filename. I thought you don't want to concatenate the files any more. Commented Feb 28, 2023 at 18:08
  • for 2. sometimes updated versions of these txt files come in later. since the destination is the same they would have the same file name and the newer one would overwrite the older one. the information could be entirely different and it would be beneficial to keep all data instead of just the most recent version of a file. Commented Feb 28, 2023 at 18:11
  • as for the end of my comment of just trying to get any .txt file, i get this response "paths must precede expression" when trying '*.txt" it seems i cant just use an asterisk and have to have some text. Commented Feb 28, 2023 at 18:14
  • You could change cp "$file" to cat "$file" >> to append each file, but this would also append if no input file was changed. You wouldn't know. And you also wouldn't know where the end of the previous file and the beginning of the new file would be. Try '*.txt'. Commented Feb 28, 2023 at 18:22