Skip to main content
added 867 characters in body
Source Link

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 all strings in a file in the same way as the example above but extract each whitespace-separated directly from the file?

Example:

fileindex=1
totalfilecount=$(cat FILE | 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 words using their index positions?

The idea is to process every word in the file as though the file were an array.

Input file example:

one two
three four
five six

Here is the scenario that requires the above funtionality:

  • we have server_A and server_B
  • server_A needs to connect to server_B via sftp (sftp only) and 'get' some files
  • BOTH 'ls' or 'ls -l' commands in sftp can be using wild cards to filter specific files
  • each file needs to be processed individually (for various reasons) on the fly
  • the files cannot be copied as a group to server_B and then processed individually
  • a list of files must first be created on server_A and then each file in that list is copied from server_B and processed one file at a time

Where is the problem?

The problem is how the 'ls' command can create a dual column list of words if the list is long thus not allowing simple processing as with 'ls -l' which always creates a single column list.

This leads us to my initial question, if such a solution exists.

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 all strings in a file in the same way as the example above but extract each whitespace-separated directly from the file?

Example:

fileindex=1
totalfilecount=$(cat FILE | 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 words using their index positions?

The idea is to process every word in the file as though the file were an array.

Input file example:

one two
three four
five six

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 all strings in a file in the same way as the example above but extract each whitespace-separated directly from the file?

Example:

fileindex=1
totalfilecount=$(cat FILE | 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 words using their index positions?

The idea is to process every word in the file as though the file were an array.

Input file example:

one two
three four
five six

Here is the scenario that requires the above funtionality:

  • we have server_A and server_B
  • server_A needs to connect to server_B via sftp (sftp only) and 'get' some files
  • BOTH 'ls' or 'ls -l' commands in sftp can be using wild cards to filter specific files
  • each file needs to be processed individually (for various reasons) on the fly
  • the files cannot be copied as a group to server_B and then processed individually
  • a list of files must first be created on server_A and then each file in that list is copied from server_B and processed one file at a time

Where is the problem?

The problem is how the 'ls' command can create a dual column list of words if the list is long thus not allowing simple processing as with 'ls -l' which always creates a single column list.

This leads us to my initial question, if such a solution exists.

clarify based on comments
Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

How to traverse a file and extract stringswords using their 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 all strings in a file in the same way as the example above but extract each stringwhitespace-separated directly from the file?

Example:

fileindex=1
totalfilecount=$(cat FILE | 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 stringswords using their index positions?

The idea is to process every stringword in the file as though the file were an array.

Input file example:

one two
three four
five six

How to traverse a file and extract strings using their 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 all strings in a file in the same way as the example above but extract each string directly from the file?

Example:

fileindex=1
totalfilecount=$(cat FILE | 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 positions?

The idea is to process every string in the file as though the file were an array.

Input file example:

one two
three four
five six

How to traverse a file and extract words using their 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 all strings in a file in the same way as the example above but extract each whitespace-separated directly from the file?

Example:

fileindex=1
totalfilecount=$(cat FILE | 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 words using their index positions?

The idea is to process every word in the file as though the file were an array.

Input file example:

one two
three four
five six
added 70 characters in body
Source Link

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 all strings in a file in the same way as the example above but extract each string directly from the file?

Example:

fileindex=1
totalfilecount=$(cat FILE | 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 positions?

The idea is to process every string in the file as though the file were an array.

Input file example:

one two
three four
five six

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 all strings in a file in the same way as the example above but extract each string directly from the file?

Example:

fileindex=1
totalfilecount=$(cat FILE | 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 positions?

The idea is to process every string in the file as though the file were an array.

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 all strings in a file in the same way as the example above but extract each string directly from the file?

Example:

fileindex=1
totalfilecount=$(cat FILE | 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 positions?

The idea is to process every string in the file as though the file were an array.

Input file example:

one two
three four
five six
deleted 8 characters in body
Source Link
Loading
deleted 8 characters in body
Source Link
Loading
2 small but opvious misspellings corrected in title and body, question mark appended to title
Source Link
Loading
Source Link
Loading