ls -la


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers ls -la
# 1  
Old 11-15-2006
ls -la

Hi All,

Can anyone help me how to change the the o/p of ls -la command under any directory in a pipe | delimited format.

Thanks,
jam
# 2  
Old 11-15-2006
ls -la <Directory Path> | tr "\n" ";"

Regards,
Sasidhar
justsam
# 3  
Old 11-20-2006
Hi Sasi,

I dont think so it will work as i required. it will just cat all the lines in to a single line with ; sepated format.
Let me brief my requirement,
if i run ls -la cmd in my current directory o/p look like
drwxrwxr-x 8 ic develop 1024 Nov 15 17:40 ./
drwxrwxr-x 11 ic develop 1024 Nov 15 16:05 ../
-rwxr-xr-x 1 ic develop 236 Nov 15 16:05 avg.sh*
-rw-rw-r-- 1 ic develop 1416 Nov 15 16:05 bak
-rw-rw-r-- 1 ic develop 2702 Nov 15 16:05 bak2
-rw-rw-r-- 1 ic develop 0 Nov 15 16:05 batch
-rw-rw-r-- 1 ic develop 37 Nov 15 16:05 bigfile
-rwxr-xr-x 1 ic develop 313 Nov 15 16:05 bintooct*
-rw-rw-r-- 1 ic develop 16184 Nov 15 16:05 cat_def
-rwxr-xr-x 1 ic develop 426 Nov 15 16:05 chessboard*
-rwxr-xr-x 1 ic develop 211 Nov 15 16:05 chk*
-rwxr-xr-x 1 ic develop 315 Nov 15 16:05 decimaltobinary*
drwxrwxr-x 3 ic develop 512 Nov 15 17:39 excer/
-rwxr-xr-x 1 ic develop 196 Nov 15 16:05 fact.sh*

i wanted to convert this mutiple, inconsistace spaces with "|" o/p should like

-rwxr-xr-x|1|ic|develop|196|Nov|15|16:05|fact.sh*

can it be done using single command in shell?

thanks,
jam
# 4  
Old 11-20-2006
this will do

Code:
ls -al | awk '{ for(i=1; i<=9; i++) { printf "%s|", $i } printf "\n" } '

# 5  
Old 11-20-2006
Sed is also handy

ls -la | sed -n 's/ */|/gp'

or

ls -la | sed -n 's/ [ \t]*/|/gp'

Cheers
rex
# 6  
Old 11-20-2006
I doubt your first command regarding the o/p required

Quote:
ls -la | sed -n 's/ */|/gp'
its much of delimiting each and every character of ls -la and not the words
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question