Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

Bash Shell Script to merge two files

Hi Experts,

I have two log files logfile A and logfile B .  I am looking for a script to delete the  starting 10 lines from logfileB and attaching it to bottom of logfile A.
  • 2
1 Solution
I can do this in a Windows batch file.  I scripted it without testing so you can have an idea. However, it should work as is. If you need further help from me, let me know.

FOR /F "usebackq skip=10 tokens=*" %%A in ("C:\path\file B.txt") DO ECHO %%A>>"C:\path\file A.txt"

In a simple DOS command line, change %% by %

I hope that helps.

Hi 07592161981m,

Judging by your topic areas, it looks as if you want a Linux shell script.

    head logfileB >>logfileA
    sed -i '1,10d' logfileB

You may run into problems if the files are being written to at the time the above commands are run, though.
An alternative reading of your question is that you want to add all of logfileB, except for the the first 10 lines, to the end of logfileA.  In that case:

    tail -n +11 logfileB >> logfileA
Good thinking, simon!

For some strange reason, i thought 07592161981m wanted to:
    "delete the starting 10 lines from logfileB"
so they are removed from it,
    "and attached it" (i.e. those 10 lines) "to bottom of logfile A".

I hope the spec's are less ambiguous next time, so experts don't waste time going down the wrong track.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now