#!/bin/sh leasestarttime="$(awk -F'.' '{print $1}' /proc/uptime 2> /dev/null)" target_file=/tmp/dhcp_client_info target_str="$INTERFACE $lease $leasestarttime" # if this interface is present in file, then replace it if grep -q "$INTERFACE" "$target_file" 2> /dev/null; then # replace the whole line if pattern matches sed -i "/${INTERFACE}/c\\${target_str}" "$target_file" else # interface info was not present, append it to the file echo "$target_str" >> "$target_file" fi