Created
September 23, 2019 16:19
-
-
Save piwwww/35bcca45bf5998ea810d5f3bd373f91c to your computer and use it in GitHub Desktop.
[template on shell script with file-ext validation]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
input_ext=".csv" | |
# simple check on input file extension | |
if [ "${1%$input_ext}" != $1 ] | |
then | |
header_file="${1%$input_ext}.header" | |
stript_file="${1%$input_ext}.noheader" | |
echo '... remove header line in' $1 | |
# a simple check on the first words of the first line | |
first_line_start_with=$(head -n 1 $1 | cut -c-5) | |
if [ $first_line_start_with = '"NPI"' ] | |
then | |
head -n 1 $1 > $header_file | |
sed '1d' $1 > $stript_file | |
else | |
echo '... (no header found in' $1 ')' | |
cp $1 $stript_file | |
fi | |
echo | |
else | |
echo "!!! please provide a $input_ext file" | |
echo "!!! exiting ..." | |
echo | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment