I am trying to load and parse a really large text file. Although the loading is not a problem, but there are particular lines that have 2908778 characters on a single line.
This is causing an error in my script.
On the script below, I removed all logic and just got straight to read line. I also removed all valid lines and just left the really long line in one text file. When running I get the below error :
$ dowhiledebug.sh dump.txt
dowhiledebug.sh[6]: no space
Script Ended dump.txt
The actual script:
#!/bin/sh
filename=$1
count=1
if [ -f ${filename} ]; then
echo "after then"
while read line;
do
echo "$count"
count=$((count+1))
done < $filename
else
echo "Could not open file $filename"
fi
echo "Script Ended $filename"
Updated (2013-01-17)
Follow up question : Is it possible to increase the maximum number of characters that ksh variable accepts?
wc -l
to count the lines in the file? It won't have the limits of the shell. I guess the answer is "because I need to do other processing which I've removed for the reproduction". – Mountainsidebash
3.2, I created a file 4194304 characters and no newline at all, and thenbash
ignored the line altogether. I appended a single newline, andbash
was quite happy to read the whole lot into memory. So, your size is not a hard limit. You'll need to look at how much memory there is on your system (more than 3 MiB, I'm sure), and whether the shell has many huge variables using up memory. – Mountainsidesysconf
value for ARG_MAX on the machine is 256 KiB, just as in the answer. I don't think the limit is directly related to ARG_MAX (though, I confess, I'm mildly surprised that I was able to echo a 4 MiB string towc
). This is on the Mac, still. – Mountainsideecho ${.sh.version}
and get a value? If so, please include in your question above. Or could this be pdksh? Good luck to all. – Ashwinver 88/f
That's part of your problem. See if you SysAdmin can point you to a newer version. If you're running on AIX, you're likely not in an environment where you can have someone build a one-off with larger ARG_MAX. It's likely time to consider another language, or analyse your processing to find another solution. Good luck. – Ashwinpython
or some other scripting language for that purpose. – Apotheosizeecho
such a large string is thatecho
is a builtin in Bash, in which case ARG_MAX doesn't apply. Compareecho "$(awk 'BEGIN { while (c++ < '"$(( $(getconf ARG_MAX) + 1 ))"') printf "=" }')"
to/bin/echo "$(awk 'BEGIN { while (c++ < '"$(( $(getconf ARG_MAX) + 1 ))"') printf "=" }')"
. That said, I too think that ARG_MAX is not relevant to the OP's problem. – Skill