1
for file in *.csv
do
  split -n 5 -d -a 1  "$file" "$file"
  for each in $(seq -w 2 3)
  do
        echo $each
        filestem="$file$each"
        len_filestem=${#filestem}
        subs=substr(len_filestem,3,4)
        echo $subs
        echo $filestem
  #awk '{filename = "wrd." int((NR-1)/10000) ".txt"; print >> filename}' $file--$each
  awk -v filestem= "{$filestem}" '{filename = substr(filestem,3,5};  print >> filename}' $filestem

  done
done

Im trying to find the substring of a string but my script is failing in substr(len_filestem,3,4)

  • Its failing in this line ---subs=substr(len_filestem,3,4) – user1050619 Apr 28 '14 at 19:11
  • 2
    substr() is an awk command, not an executable. – jayhendren Apr 28 '14 at 19:11
  • You probably want subs=${len_filesystem:3:4} – doneal24 Apr 28 '14 at 19:25
  • 1
    Is there any good reason to talk about an error message but not adding it to the question? – Hauke Laging Apr 28 '14 at 19:25
1

The error is the space after the =:

-v filestem= "{$filestem}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.