This has been driving me crazy...
I want to list files in a dir and, based on the number interate on all files except the latest one, here is the code snipplet
FILECOUNT=$(ls -lt [dir]*.log | grep -c .log )
for (( c=2; c<=$FILECOUNT; c++ ))
do
FILEDIR=$("ls -1t [dir]*.log | sed -n '$c p'")
I have been having issues with $c
interpretation, the format above works but the sed command fails... although entering the last line of the log in the cli works like a charm
FILECOUNT=24
(( c=2 ))
(( c<=24 ))
C is : 2
'ls -1t [dir]*.log | sed -n '''2 p''''
line 41: ls -1t [dir]*.log | sed -n '2 p': No such file or directory
any help would be greatly appreciated!
the [dir]
is obviously a valid directory
zsh
where you can order and select files by modification time using glob qualifiers ex.for f in dir*.log(Om[1,-2]); do
orfor f in dir*.log(om[2,-1]); do
. See Why not parsels
(and what to do instead)? – steeldriver Jun 02 '21 at 12:55