拆分shell脚本卡住

时间:2017-05-29 04:10:39

标签: bash macos shell csv

我编写了以下脚本来尝试自动执行我的CSV文件导入并继续卡在最后一个分割功能上。脚本运行并询问$ lines输入但未完成。我希望脚本保留原始文件的标题并输出到生成的文件。

    #!/bin/bash


function get_file() {
  # get file name
  read -e -p "Enter the name of the file   " file #ENTER FILE NAME
}

function file_check() {
  #check for supported filetype

  if [[ $file == *.csv ]]; #VALIDATE CSV FILE
      then  echo $file looks good! Lets go...

  else

      if [[ $file == *.xls ]] || file == *.sxls ]] || [[ $file == *.txt ]]; #CHECK FOR CONVERSION
        then echo You entered: $file, this file needs to be converted to csv!
    fi
  fi
}
#RE-ENTER FILE NAME
function file_validate() {
  while ! [ -e $file ]; do
  echo No such file, Enter a valid file name!
  get_file
done
}

# SHOW FILE DETAILS
function file_detail() {
  csvlstat --count $file
}

function split() {

  read -e -p "Enter the name of the new file   " new
  read -e -p "Enter the number of records for each file   " lines
  tail -n +2 $file | split -l $lines - split_
  for new in split_*
  do
      head -n 1 $file > tmp_file
      cat $new >> tmp_file
      mv -f tmp_file $new
  done

}

0 个答案:

没有答案