def dynamic_diff_create_running_config(device, mapping, template, base_config):
    """ Creates a merged running config from template dynamic diff with
        variables replaced by mapping and merged with base config
        Args:
            mapping ('dict'): Variable to interface mapping
            ex.) {'{{ int_1 }}': 'Ethernet2/1-48', '{{ int_2 }}': 'Ethernet5'}
            template ('str'): Content of the dynamic diff template
            base_config ('str'): Content of the base config
        Raise:
            None
        Returns:
            Config ('str'): The merged running config from template
    """
    for variable, value in mapping.items():
        template = template.replace(variable, value)

    # Remove all end markers if any
    template = template.replace('\nend \n', '\n')
    template = template.replace('\nend\n', '\n')
    if template.endswith('\nend'):
        template = template[:-4]
    if template.endswith('\nend '):
        template = template[:-5]

    return '{}{}'.format(template, base_config)