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)

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

1 Answer 1

1

The error is the space after the =:

-v filestem= "{$filestem}"

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.