Visit Our UNIX and Linux User Community


need help with displaying only names using ls -l


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help with displaying only names using ls -l
# 1  
Old 08-03-2010
need help with displaying only names using ls -l

Hi I am kind of stuck

I need help with printing only the names of the folder in the format

LAST NAME, F

so last name and the first character of first name

using ls -l command in the /home directory

currently they are in the format firstname.lastname


please advice
# 2  
Old 08-03-2010
Try:
Code:
ls -l | awk '/^d/{split($NF,N,".");print N[2]", "substr(N[1],1,1)}'

or
Code:
ls -l | sed -n '/^d/{s/.* \(.\).*\.\(.*\)/\2, \1/p}'

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 08-03-2010
Quote:
Originally Posted by Scrutinizer
Try:
Code:
ls -l | awk '/^d/{split($NF,N,".");print N[2]", "substr(N[1],1,1)}'


thanks for your reply.

is there a way of doing it with out using awk ?
# 4  
Old 08-03-2010
Quote:
Originally Posted by classic
thanks for your reply.

is there a way of doing it with out using awk ?
Hi,
I posted a sed alternative as well would that work? What are you looking for?
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 08-03-2010
Thanks thats brilliant it all worked perfectly.

Previous Thread | Next Thread
Test Your Knowledge in Computers #883
Difficulty: Easy
A computer security vulnerability is a weakness in design, implementation, operation or internal control.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

2. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

3. Solaris

Characters not displaying

Hi, Does anyone know what i need to do to get the '' character to display on a Solaris 9 server. When i try to cut and paste it onto some of my machines via telnet it displays an 'i' but other machines with the same OS version are ok. It also doesn't like Japanese Characters. Any help would be... (0 Replies)
Discussion started by: mwfisher
0 Replies

4. UNIX for Dummies Questions & Answers

Displaying VERY long process names with ps -ef

Hi, I'm trying to display all process on an AIX server with the string SLRServer in them. Normally "ps -ef|grep SLRServer" would be sufficient, however in this instance the process name is enormous and the part which contains this string has been truncated, as you can see in the example below ... (8 Replies)
Discussion started by: m223464
8 Replies

5. Shell Programming and Scripting

Displaying files

I am beginner to UNIX. I wanted to display 5 filesname with size from BIN directory. The order of display should be descending order in size. Can help me. (1 Reply)
Discussion started by: giridher2000
1 Replies

6. UNIX for Dummies Questions & Answers

Displaying file names before a particular creation date

Hi!! I wanna display file names which are created before/after a particular date. I wud be glad if anybody can help me out in that. Thanx Dhruv (1 Reply)
Discussion started by: dhruv_saksena
1 Replies

7. UNIX for Dummies Questions & Answers

displaying with ls

hi, how can display year parameter also while listing files from a directory?it displyas only if last acces sis more than 1 yr i guess.can it be dispalyed using some option or some method? thanks and regards vivek.s (2 Replies)
Discussion started by: vivekshankar
2 Replies

8. SCO

vi editor not displaying?

Hi guys, I have changed some path in the vi .profile and then i shutdown the system and when i reboot it i was unable to use vi. It is showing vi not found.Likewise for few other commands also. How to solve this problem and make vi work again. Plz. do provide the answer it is... (3 Replies)
Discussion started by: ananthu_m
3 Replies

9. UNIX for Dummies Questions & Answers

Displaying what a command is doing/has done

I would like to see what a command is doing. For example, say I move 10 files using mv * somedir. Can I use some other command to see a verification of each files movement. Like: file1 moved to somedir file2 moved to somedir ... but, i'd to have this capability for all commands. it seems... (1 Reply)
Discussion started by: quantumechanix
1 Replies

10. Shell Programming and Scripting

displaying date

Hi All, When I type date..I get the date, time ..etc displayed ...but can someone help me to display yesterdays date... some script to display back dates. Thanks in advance Minaz (7 Replies)
Discussion started by: minazk
7 Replies

Featured Tech Videos