Accessing Multiple files using for loop

Hi All,

I have some files in my directory, and i want to pull all data using for loop....I am using following code but getting error..!

for file in {file1, file2, file3, ..... filen}
do
 L="$(tail -1 $file)";NUM=${L%%|*};DAT=${L##*|}
 echo $NUM>>filedata.txt
done

Error:

tail: cannot open input
tail: cannot open input

i tried with other codes, some gave blank data and some something else.....but can understand where the prob is.... :frowning:

please help

Try:

for file in file1 file2 .. filen
[...]

Or:

for file in <glob pattern>
[...]

For example, if your files are named file1, file2 ..:

for file in file*
[...]

It's a good practice to quote your variables too:

tail -1 "$file"

try with:

for file in "file1" "file2" "file3" ... "filen"

Thanks a lot........now its working for me...!!

i used file in "file1" 'file2".......!

NB:Please let me know how can i close threads if my issue gets resolved.