#!/bin/sh

die() {
	echo $@
	exit 1
}

[ $# -ne 1 ] && die "Usage: $(basename $0) <file-fo-convert>"
[ -r $1 ] || die "File \"$1\" is unreadable"

get_out() {
	local _in=$1
	local _suffix=$2
	local _name_ext=$(basename ${_in})
	local _dir=$(dirname ${_in})
	local _ext=$(echo ${_name_ext} | sed -e 's/.*\.//')
	local _name=$(echo ${_name_ext} | sed -e 's/\..*//')
	[ "${_name}" = "${_name_ext}" ] && \
		echo "${_dir}/${_name}${_suffix}" \
		|| \
		echo "${_dir}/${_name}${_suffix}.${_ext}"
}

cat $1 | grep -v "OutgasTemp" | sed -e 's/\ *Sample\ Volume.*//' -e 's/ЕІ/Angstrom^2/g' -e 's/Е/Angstrom/g' -e 's/mІ/m^2/g' > $(get_out $1 "-nossv")
