modify ls -l (long listing format output) strictly using SED only straightforward goalhard 4 me doh

Below is a sample out of ls -l which I would like to rearrange or modify by field numbers for example I successfully managed to disect using simple paragraph however for ls -l I can't divide the rows or fields by field number.

Successful modification by fields using SED sample:

[localuser@localhost ~]$ sed -e 's/^\(.*\) \(.*\) \(.*\) \(.*\) \(.*\)/1stString (\1) 2ndWord (\2) 3rdWord (\3) 4thWord (\4) 5thWord (\5)/' maryhad
1stString (Mary) 2ndWord (had) 3rdWord (a) 4thWord (little) 5thWord (lamb.)
And everywhere that Mary
1stString (went, the lamb) 2ndWord (was) 3rdWord (sure) 4thWord (to) 5thWord (go.)
Mary was not Mary'd

#Beta Script not functioning like the one above: not dividing the strings as I intended::wall:

[localuser@localhost ~]$ head -3 tabc.txt | sed -e 's/^\(.*\) \(.*\) \(.*\) \(.*\) \(.*\)/1stString (\1) 2ndWord (\2) 3rdWord (\3) 4thWord (\4) 5thWord (\5)/'
)stString (-rwx------- 1 alice   staff     1586) 2ndWord () 3rdWord (2010-11-05) 4thWord (02:27) 5thWord (request-key.conf
)stString (-rwx------- 1 ted   staff     126) 2ndWord () 3rdWord (2011-04-29) 4thWord (13:54) 5thWord (cvs-pserver.conf
)stString (-rwx------- 1 carol   staff     644) 2ndWord () 3rdWord (2011-03-06) 4thWord (21:58) 5thWord (ts.conf

straightforward goal/intent:

separate long listing format fields output of ls using SED only please.

Thank you and welcome for suggestions

Try this:

sed -e 's/^\([^ ]*\)  *\([^ ]*\)  *\([^ ]*\)  *\([^ ]*\)  *\([^ ]*\)/1stString (\1) 2ndWord (\2) 3rdWord (\3) 4thWord (\4) 5thWord (\5)/'

For files with spaces in their name consider -Q (quote name) option of ls.

1 Like