Looping thru tab delimited data

Hello people,
Can you please tell me how to loop thru the contents of a variable having tab delimited data using for loop in KSH.

For example:
data1 data2 data3 data4

How can I access the above data in a for loop? Please let me know. Thanks.

Regards,
T.

Got the solution. A simple for loop worked. thanks.

Regards,
T.

Willing to share it? :slight_smile:

Here it is:

files=`ls -1 $dir`

for file in `echo $files`
do
echo $dir/$file
done

-- I wanted to list the files in a folder and use that list for further processing. Instead of taking the filenames into a file, I take it into a variable. The filenames here are tab delimited.

Regards,
T.

You certainly don't need to create "ls" and "echo" processes since KSH enables you to get your file list right from the for loop.

for file in $dir/*
do
     echo $file
done

This produces the same output with simpler logic.

The reason I was doing it that was for my code I need the filenames in bare format i.e just the file name without path.
Maybe I will use the basename function to extract just the filename.

Thanks tmarikle.

Or again, without using another process and using a KSH built in capability:

for file in $dir/*
do
   echo ${file##*/}
done

This will do the same as basename.