how do you display/manipulate all the filenames in a dir one at a time
or feed the results of the ls command into an array?

I'm working on a script that modifies file names and does some other stuff.

normally you can just do a for loop across all the filenames in the directory.

The problem is I'm using sed and awk to manipulate the file names before doing other actions with them. So I somehow need to display or read the file names one at a time. Here are two simplified versions of the script which kinda work, but not fully.



#!/bin/bash
#script name: ls_script.sh
#using ls
ls | sed 's/_/\ /' | awk '{print $2,"\t",$3,"\t",$4 }'


#!/bin/bash
#script name: cat_script.sh
#attempting to use cat
for file in *.txt
do
cat file | sed 's/_/\ /' | awk '{print $2,"\t",$3,"\t",$4 }'
#other actions using output
done

results of scripts:
$ls
file_1_3212011_test10
file_2_3212011_test11
file_3_3212011_test12

$./ls_script.sh
1 3212011 test10
2 3212011 test11
3 3212011 test12

$./cat_script.sh
pages and pages of data from file1
pages and pages of data from file2
pages and pages of data from file3


I still feel like I didn't explain it well.