Hey,
Using only grep and sed, is there a way I can tranform the output of ls -l *
into this :
-rw-r--r-- agenda.txt
-rw-r--r-- annuaire.txt
Thanks!
Hey,
Using only grep and sed, is there a way I can tranform the output of ls -l *
into this :
-rw-r--r-- agenda.txt
-rw-r--r-- annuaire.txt
Thanks!
Like this?
ls -l | sed 's/ [0-9].*:.[0-9] / /' | less
Transforms
-rw-r--r-- 1 tomislav tomislav 609 2009-11-26 10:32 Test.class
-rw-r--r-- 1 tomislav tomislav 46 2009-12-14 12:16 test.groovy
into
-rw-r--r-- Test.class
-rw-r--r-- test.groovy
seeing that you have already got your "answer", here's one of the simpler solution
ls -l | tr -s " "| cut -d" " -f1,8-
@OP, sed is "powerful", but sometimes, simplicity is more powerful
.
Side note: Don't parse file names like that.
Here is a working command. The slightly tricky thing is that ls -l
will print the year for files that are older than some time (6 months) and hh:mm
for newer files.
ls -l | sed 's/ .*[0-9]* .*[A-Z][a-z][a-z] [ 0-9][0-9] \{1,2\}[0-9][0-9]:*[0-9][0-9] / /'
For the following example
drwxr-xr-x 39 root root 1024 Feb 19 08:58 /
the starting .*
will match 39 root root 1024
and then the rest of the regular expression matches month name (so you might restrict a-z to fewer characters) followed by year or hh:mm.