diff --git a/README.md b/README.md index 769bc34e274e16b610f89ee385e247919c91f996..4c0efbb226d5b96a724c4abd7cc70666b02e9ac2 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,11 @@ Check for updated versions (more recent release tags) at https://gitlab.pasteur. #### WHAT'S NEW IN +## v1.3.0 + +test_column_nb_perline_in_file_fun with better writting + + ## v1.2.0 output file name error in test_column_nb_perline_in_file_fun fixed diff --git a/little_bash_functions.sh b/little_bash_functions.sh index 53f0656477b267d46728094396b06b2bc1a607d7..06a48195e00aeee5fc2a66c33c24c79c87b22b78 100644 --- a/little_bash_functions.sh +++ b/little_bash_functions.sh @@ -2,7 +2,7 @@ ################################################################ ## ## -## LITTLE BASH FUNCTIONS v1.2.0 ## +## LITTLE BASH FUNCTIONS v1.3.0 ## ## ## ## Gael A. Millot ## ## ## @@ -309,14 +309,14 @@ function test_column_nb_perline_in_file_fun () { ((OPTIND--)) # or ((OPTIND-1)) ? fi } - local OPTIND OPTION i o d l INPUT_FUN OUTPUT_FUN OUTPUT_WOPATTERN_FUN CHARACTER_FUN + local OPTIND OPTION i o d l INPUT_FUN OUTPUT_ERROR_FUN OUTPUT_WO_ERROR_FUN CHARACTER_FUN while getopts ":i:o:c:d:" OPTION ; do # add : after the option name to specify that something is required (-h has nothing required after) # the first : before h is to induce getopts switching to "silent error reporting mode" (disable annoying messages). case $OPTION in i) verif $OPTARG ; INPUT_FUN=$OPTARG ;; - o) verif $OPTARG ; OUTPUT_FUN=$OPTARG ;; - c) verif $OPTARG ; OUTPUT_WOPATTERN_FUN=$OPTARG ;; + o) verif $OPTARG ; OUTPUT_ERROR_FUN=$OPTARG ;; + c) verif $OPTARG ; OUTPUT_WO_ERROR_FUN=$OPTARG ;; d) verif $OPTARG ; CHARACTER_FUN=$OPTARG ;; \?) echo -e "\n### test_column_nb_perline_in_file_fun ERROR ### INVALID OPTION\n" ; return 1 ;; :) echo -e "\n### test_column_nb_perline_in_file_fun ERROR ### OPTION -${OPTARG} REQUIRES AN ARGUMENT\n" ; return 1 ;; @@ -331,18 +331,18 @@ function test_column_nb_perline_in_file_fun () { echo -e "\n### test_column_nb_perline_in_file_fun ERROR ### ${INPUT_FUN} FILE NOT PRESENT IN `dirname $INPUT_FUN`\n" return 1 fi - if [[ -z $OUTPUT_FUN ]]; then - local OUTPUT_FUN=${INPUT_FUN}_error_line + if [[ -z $OUTPUT_ERROR_FUN ]]; then + local OUTPUT_ERROR_FUN=${INPUT_FUN}_error_line fi - if [[ -f $OUTPUT_FUN ]]; then - echo -e "\n### test_column_nb_perline_in_file_fun ERROR ### ${OUTPUT_FUN} FILE ALREADY EXISTS\n" + if [[ -f $OUTPUT_ERROR_FUN ]]; then + echo -e "\n### test_column_nb_perline_in_file_fun ERROR ### ${OUTPUT_ERROR_FUN} FILE ALREADY EXISTS\n" return 1 fi - if [[ -z $OUTPUT_WOPATTERN_FUN ]]; then - local OUTPUT_WOPATTERN_FUN=${INPUT_FUN}_wo_error_line + if [[ -z $OUTPUT_WO_ERROR_FUN ]]; then + local OUTPUT_WO_ERROR_FUN=${INPUT_FUN}_wo_error_line fi - if [[ -f $OUTPUT_WOPATTERN_FUN ]]; then - echo -e "\n### test_column_nb_perline_in_file_fun ERROR ### ${OUTPUT_WOPATTERN_FUN} FILE ALREADY EXISTS\n" + if [[ -f $OUTPUT_WO_ERROR_FUN ]]; then + echo -e "\n### test_column_nb_perline_in_file_fun ERROR ### ${OUTPUT_WO_ERROR_FUN} FILE ALREADY EXISTS\n" return 1 fi if [[ -z $CHARACTER_FUN ]]; then @@ -364,29 +364,29 @@ function test_column_nb_perline_in_file_fun () { echo -e "\n### test_column_nb_perline_in_file_fun ERROR ### THE FIRST LINE OF $INPUT_FUN IS EMPTY: USE file_pattern_detection_fun TO REMOVE EMPTY LINES\n" return 2 fi - awk -F "$CHARACTER_FUN" -v var1=$NB_COL_FIRSTLINE 'NF!=var1{print NR, $0}' $INPUT_FUN > ${OUTPUT_FUN} # recover the error lines - awk -F "$CHARACTER_FUN" -v var1=$NB_COL_FIRSTLINE 'NF==var1{print $0}' $INPUT_FUN > $OUTPUT_WOPATTERN_FUN + awk -F "$CHARACTER_FUN" -v var1=$NB_COL_FIRSTLINE 'NF!=var1{print NR, $0}' $INPUT_FUN > ${OUTPUT_ERROR_FUN} # recover the error lines + awk -F "$CHARACTER_FUN" -v var1=$NB_COL_FIRSTLINE 'NF==var1{print $0}' $INPUT_FUN > $OUTPUT_WO_ERROR_FUN # rm $INPUT_FUN - local NB_ERROR_LINES=$(wc -l < "${OUTPUT_FUN}") # number of error lines + local NB_ERROR_LINES=$(wc -l < "${OUTPUT_ERROR_FUN}") # number of error lines if [[ $NB_ERROR_LINES == 0 ]] ; then echo -e "\ntest_column_nb_perline_in_file_fun MESSAGE: NO DIFFERENT COLUMN NUMBER FOUND IN LINES OF ${INPUT_FUN} HAVING $NB_COL_FIRSTLINE COLUMNS IN THE FIRST LINE\n" - rm ${OUTPUT_FUN} - rm ${OUTPUT_WOPATTERN_FUN} + rm ${OUTPUT_ERROR_FUN} + rm ${OUTPUT_WO_ERROR_FUN} return 0 elif [[ $NB_ERROR_LINES == $(( ${TOTAL_NB_LINES} - 1 )) ]]; then echo -e "\ntest_column_nb_perline_in_file_fun MESSAGE: ONLY THE FIRST LINE HAS A DIFFERENT COLUMN NUMBER FROM THE REST OF THE ${INPUT_FUN} FILE\nTHE FIRST LINE IS:\n$(head -n 1 $INPUT_FUN)" - rm ${OUTPUT_FUN} - rm ${OUTPUT_WOPATTERN_FUN} + rm ${OUTPUT_ERROR_FUN} + rm ${OUTPUT_WO_ERROR_FUN} return 3 else - echo -e "test_column_nb_perline_in_file_fun MESSAGE: ${NB_ERROR_LINES} LINES FOUND IN ${INPUT_FUN} SHOWING A NUMBER OF COLUMN DIFFERENT FROM $NB_COL_FIRSTLINE COLUMNS AS FOUND IN THE FIRST LINE\n" # | tee -a $OUTPUT_FUN - # echo -e "THE PROBLEMATIC LINES ARE:\n" >> $OUTPUT_FUN + echo -e "test_column_nb_perline_in_file_fun MESSAGE: ${NB_ERROR_LINES} LINES FOUND IN ${INPUT_FUN} SHOWING A NUMBER OF COLUMN DIFFERENT FROM $NB_COL_FIRSTLINE COLUMNS AS FOUND IN THE FIRST LINE\n" # | tee -a $OUTPUT_ERROR_FUN + # echo -e "THE PROBLEMATIC LINES ARE:\n" >> $OUTPUT_ERROR_FUN if(( ${NB_ERROR_LINES} <= 200 )) ; then # display if less than 200 echo -e "\ntest_column_nb_perline_in_file_fun MESSAGE: THE PROBLEMATIC LINES ARE:\n" - cat ${OUTPUT_FUN} + cat ${OUTPUT_ERROR_FUN} echo -e "\n\n" else - echo -e "\ntest_column_nb_perline_in_file_fun MESSAGE: THE PROBLEMATIC LINES ARE MORE THAN 200 -> ONLY PRINTED IN THE $OUTPUT_FUN FILE:\n" + echo -e "\ntest_column_nb_perline_in_file_fun MESSAGE: THE PROBLEMATIC LINES ARE MORE THAN 200 -> ONLY PRINTED IN THE $OUTPUT_ERROR_FUN FILE:\n" fi return 4 fi