Enumerate ls -l output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Enumerate ls -l output
# 1  
Old 08-31-2009
Enumerate ls -l output

Hi, I'm using normally ls -l to get the content of a directoy.

But, it's possible to enumerate the ls output ? (like put the line number at the begining of each line)

If it wasn't possible (I don't hope so ...), there's a way to get the line number the line had after doing a grep:
ls -l /directory | grep word ----> and then get the line number it had in the ls output ...

Thanks in advance
# 2  
Old 08-31-2009
Try:
Code:
j=1; for i in *; do  echo $(( j++ )) $i; done

Code:
j=1; for i in *; do  echo $(( j++ )) $(ls -l $i); done

# 3  
Old 08-31-2009
Try awk
Code:
ls -l | awk '/word/{print ++c, $0}'

# 4  
Old 08-31-2009
Quote:
Originally Posted by tecnitek
Hi, I'm using normally ls -l to get the content of a directoy.

But, it's possible to enumerate the ls output ? (like put the line number at the begining of each line)

Code:
ls -l | pr -Tn

Quote:

If it wasn't possible (I don't hope so ...), there's a way to get the line number the line had after doing a grep:
ls -l /directory | grep word ----> and then get the line number it had in the ls output ...

Why would you use grep instead of giving ls a pattern?
# 5  
Old 09-01-2009
Quote:
Originally Posted by tecnitek
But, it's possible to enumerate the ls output ? (like put the line number at the begining of each line)

Thanks in advance
Hi, the program nl enumerates lines so You can pipe the output through it, like

Code:
ls -l | nl

/Lakris

PS If You use
Code:
ls -l | nl -v 0

it will actually enumerate the actual files if that is desirable.

Last edited by Lakris; 09-01-2009 at 01:37 AM.. Reason: a PS
# 6  
Old 09-01-2009
or..
Code:
# ls -1 | grep -n .
1:dir_7851
2:dir_license_7851_20081017
3:bin
4:cdrom
5:dev
6:devices
7:test
8:esm
9:etc
10:export
11:home
12:hosts
13:javahost.pid
14:java_install
15:kernel
16:lib
17:lost+found
18:media
19:mnt
20:net
21:netegrity
22:opt
23:platform
24:proc
25:root
26:sbin
27:system
28:tmp
29:u01
30:unused
31:usr
32:var
33:vol
34:xfn

# 7  
Old 09-01-2009
or..

Code:
ls -l | awk '{print NR,$0}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Enumerate disk instances in Solaris

HI, I need to find out what are all the hard disks connected in my System on Solaris? Also on my system when I ran the command prtconf, the following output is displayed. sd (driver not attached) st (driver not attached) sd, instance #0 (driver not attached) sd, instance... (1 Reply)
Discussion started by: rajujayanthy
1 Replies

2. Shell Programming and Scripting

Enumerate lines until each line break using awk

Hi, I have the following data: This this DT 0.99955 0 4 is be VBZ 1 5 7 sentence sentence NN 0.916667 8 16 one one NN 0.545078 17 20 . . Fp 1 20 21 This this DT 0.99955 22 26 is be VBZ 1 27 29 the the DT 1 30 33 second 2 JJ 0.930556 34 40 sentence sentence NN 0.916667 41 49... (1 Reply)
Discussion started by: owwow14
1 Replies

3. Red Hat

Command understanding the output file destination in case of standard output!!!!!

I ran the following command. cat abc.c > abc.c I got message the following message from command cat: cat: abc.c : input file is same as the output file How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Discussion started by: ravisingh
3 Replies

4. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

5. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

6. Shell Programming and Scripting

How to enumerate mounted disks and place output in array ?

Hi. I'm new to scripting / programming and was wondering what the best way to output all mounted storage devices and their names to an array would be ? I would like to achieve this using the bash shell. Any assistance with this would be greatly appreciated. Regards, Jonno :b: (4 Replies)
Discussion started by: Jonno888
4 Replies

7. UNIX for Advanced & Expert Users

How to enumerate USB Mass Storage devices?

Hi all, I want to write a program in C that can enumerate all USB massand their mount point storage on my system. i want to give ability to copy one file to desired USB mass storage or read a file from it. I have posted another question about how can recieve USB arrival in this forum. I think... (0 Replies)
Discussion started by: aghashahi
0 Replies

8. Programming

enumerate processes

Again for windows I can enumerate processes using toolhelp library PROCESSENTRY32 pe32 = {0}; HANDLE hsp = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); pe32.dwSize = sizeof( PROCESSENTRY32 ); Process32First( hsp, &pe32 ); do { // access ... (2 Replies)
Discussion started by: gyula
2 Replies

9. Shell Programming and Scripting

how to make a line BLINKING in output and also how to increase font size in output

how to make a line BLINKING in output and also how to increase font size in output suppose in run a.sh script inside echo "hello world " i want that this should blink in the output and also the font size of hello world should be big .. could you please help me out in this (3 Replies)
Discussion started by: mail2sant
3 Replies

10. IP Networking

How to enumerate samba shares with client

I have a samba server node and I want to mount the samba (CIFS) shares from a second (client) unix machine. However, the unix mount command requires I specify the name of the share. What if I don't know the name of the share? How can I enumerate all the shares from the samba client machine? ... (1 Reply)
Discussion started by: siegfried
1 Replies
Login or Register to Ask a Question