Skip to main content
1 of 7

How to traverse a file and extract strings using there index

The given file must NOT be stored in variable and then traversed due to memory size restrictions:

Example:

var=$(cat file)
for i in $var
do
  echo $i
done

How do you traverse the file itself in the same way as the example above but extract each string directly from the file?

Example:

fileindex=1
totalfilecount=$(cat ${filesfile} | wc -w)
while (( ${fileindex} <= ${totalfilecount} ))
do
  onefilename= ??? missing command using fileindex
  ((fileindex+=1))
done

Is there a command that can view a file as an array and allow you to extract strings using their index possitions?