3

I have a list of files starting with L- and a folder called L with inside files with the same name, for instance L-some and L/L-some.

For each file L- I want to merge append its content into L/L-. I have tried with this, but is not working.

for f in L-*; do "cat L/$f $f > L/$f"; done

What's wrong?

  • You are basically rewriting each file with that >. Use >> to append as heemayl showed – Sergiy Kolodyazhnyy Sep 24 '16 at 22:42
7

Do:

for f in L-*; do cat "$f" >>L/"$f"; done

This gets each L- file in the current directory (L-*) and append (>>) its content (cat "$f") in the file with same name in L directory (cat "$f" >>L/"$f").

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.