Bash Shell Script to merge two files

Posted on 2012-09-19
Last Modified: 2012-09-20
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.
Question by:07592161981m
    LVL 10

    Expert Comment

    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.

    LVL 11

    Expert Comment

    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.
    LVL 19

    Accepted Solution

    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
    LVL 11

    Expert Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now