Instead of parsing the output of ls -l (which is pretty error-prone, locale-dependent and all), why not find a command that gives you the desired output directly?
(Yes, I know. Sorry for the bad pun.)
# -maxdepth 1: Maximum recursion depth (1 == current directory only).
# -type f: Files only (no directories).
# -name ...: Name pattern of files to list. Escape the \* so the shell does not.
# -printf ...: Format of the listing, printf() style:
# %M: File permissions, symbolic view. Use %m for octal.
# %n: Number of hard links to file.
# %u: User name if present, or numeric ID. Use %U for numeric ID only.
# %g: Group name if present, or numeric ID. Use %G for numeric ID only.
# %s: File size in bytes. Use %b for 512-byte blocks, %k for 1k blocks.
# %Tm: Last modification timestamp, month (01..12).
# %Td: Last modification timestamp, day (01..31).
# %TH: Last modification timestamp, hour (00..23). (Yanks use %TI and %Tp.)
# %TM: Last modification timestamp, minute (00..59).
# %p: Filename.
find . -maxdepth 1 -type f -name \*.dat -printf "%M,%n,%u,%g,%s,%Tm,%Td,%TH:%TM,%p\n"
Check man find for more options to -printf, and find in general. (Be especially careful with the date / time fields, since you aren't querying the year here...)
Gratuitious time data quiz question: What is the range of values for %Ts (modification time, seconds)?
- 00..59? Wrong.
- 00..60? Wrong.
- 00..61? Correct.
If you don't know why, better read up on "leap seconds" if you want to write stable time-stamp parsing code. ;-)
input1="output.txt"does not make sense, it should beinput1=$(cat output.txt). But in fact you can just dowhile ... do ... done < output.txtIFS=' 'is necessary.