Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've written the script below to merge only .txt files that exist in one directory into one huge .txt file and ignore other files with other extensions.
now the result is one huge .txt file with all the contents of other .txt files
how can i add the File Name as a comment before each file?
I didn't think that find would replace instances of '{}' in a single argument string. Does that really work?
I'm not sure what do you mean as "single argument string". It is replaced by every item found and the command is executed multiple times over each argument. This is because of the trailing \; (escaped semicolon). On the other hand, if you use + (plus sign) the arguments are substituted all together and the command is executed only once:
Quote:
-exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built
by appending each selected file name at the end; the total number of invocations of the command will be much less
than the number of matched files. The command line is built in much the same way that xargs builds its command
lines. Only one instance of `{}' is allowed within the command. The command is executed in the starting direc-
tory.
OFFTOPIC: what does that bold part stand for? What is his purpose?
It matches the requirements from the OP:
Quote:
how can i add the File Name as a comment before each file?
//FileName
I think s/he wanted to put some easily recognizable symbol in front of the file names in order to use the searching tools of whatever text editor s/he uses. And I agree with grail... the bold style inside code tags is almost indistinguishable from the rest... and my sight is eagle-like, despite my age!
Seriously, the escaping in this case is an overkill, since the slashes are correctly passed to the invoked shell and they have no special meaning in this context. It was a sort of habit... maybe I was thinking about slash delimited regular expressions at that point! Indeed they are superfluous, here.
I mean that the argument contains {}, it's not "{}" alone.
You can have multiple instances of {} in the exec command. The only caveat is that the argument {} is not correctly passed to command substitutions, that is the reference to the item is lost when spawning a subshell.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.