Problem: I have a CSV dump file - with excess of 250,000 lines. When I use while read
- it takes a while (no pun intended). I would like to go back to the last 10,000 lines to do what I need to do instead of the 250,000 lines.
Code Snippet: My current code is this:
IFS=","
while read line
do
awk_var=`echo "$line" | awk -F" " '{print $0}'`
var_array=($awk_var)
read -a var_array <<< "${awk_var}"
echo "${var_array[1]}"
done </some_directory/directory/file_in_question.csv
Question: How can I use tail -n10000
with while read line
when reading the file_in_question.csv
with a bash script?
{print $0}
is the same as{print}
to awk which is the same as not using awk at all. What were you trying to do there? And the time here is likely from the 250,000 calls toawk
(once per-loop). Avoid those if you can. – Guinnaawk_var=$(echo "$line" | awk -F " " '{print $0}')
is exactly the same asawk_var=$(echo "$line")
which is exactly the same asawk_var=$line
which is the same as just using$line
in the first place only with two fewer external commands, one less sub-shell and a few fewer lines of code. Alsovar_array=($awk_var)
is wrong and you overwriteawk_var
with theread
a line later. – Guinna