Skip to main content
14 events
when toggle format what by license comment
Mar 1, 2023 at 0:14 comment added linuxuser24569 After some modifications, this works awesome: cat "$file" "$targetdir/$(realpath --relative-base=. "$file" | cut -d'/' -f-2 | tr '/' '_')" It keeps the text from the folder that holds the unique identifier which is what I was trying to do the whole time. Now, if its possible to append the actual file name onto the end of this that would be a homerun. With this command my filename currently appears like: a_aRFGHsvbfbv now, if we can just append the .txt file on the end, it would be like a_aRFGHsvbfbv_file.txt.
Feb 28, 2023 at 22:29 comment added Freddy Yes, -f-5 means the first 5 fields between separator character / are cut which is 4 directories plus filename (since they were reversed with rev). A lot of things are possible, but not today :) Please test if you can make it work with this fix. I think the last directories are the most important ones to find your files.
Feb 28, 2023 at 22:20 comment added linuxuser24569 Perfect, how can I test this out? is it here: -f-5 ? Just change the number? Also is it possible to take the 2nd directory and the last directory (out of a path of 6 directories, for example)?
Feb 28, 2023 at 22:14 comment added Freddy See my edit to restrict the filename to the last 4 directories. You can write the two lines on one line if you want.
Feb 28, 2023 at 22:13 history edited Freddy CC BY-SA 4.0
added alternative for shorter filename
Feb 28, 2023 at 21:14 comment added linuxuser24569 Hey Freddy, can you show me where in the command it writes the path into the new filename? I'm getting a new issue now where some filenames are too long. I wonder if its possible only to grab part of the path name to write in and not the full thing to cut down the file name length?
Feb 28, 2023 at 21:13 comment added linuxuser24569 Using double quotes worked: "*.txt"
Feb 28, 2023 at 18:49 vote accept linuxuser24569
Feb 28, 2023 at 18:22 comment added Freddy 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'.
Feb 28, 2023 at 18:14 comment added linuxuser24569 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.
Feb 28, 2023 at 18:11 comment added linuxuser24569 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.
Feb 28, 2023 at 18:08 comment added Freddy 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.
Feb 28, 2023 at 17:57 comment added linuxuser24569 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?
Feb 28, 2023 at 17:23 history answered Freddy CC BY-SA 4.0