Link to home
Start Free TrialLog in
Avatar of 07592161981m
07592161981m

asked on

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.
Avatar of ReneGe
ReneGe
Flag of Canada image

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.

Cheers,
Rene
Avatar of tel2
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.
ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

tel2