#!/bin/bash res="" buf="" while IFS="" read str do if [ -z "${str##* *}" ] then key="${str%% *}" val="${str#* }" else key="${str}" val="" fi if [ -z "${key}" ] then buf="${buf}"$'\n'"${val}" elif [ -n "${buf}" ] res="${res}$(echo -n "${buf}" | $1)" buf="${val}" fi done if [ -n "${buf}" ] res="${res}$(echo -n "${buf}" | $1)" buf="${val}" fi echo -n "${res}"