blocking only path in ls command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting blocking only path in ls command
# 1  
Old 07-04-2011
blocking only path in ls command

I want to block the path while listing the files is it possible to do it , i tried with awk but it blocks everything (details such as owner n filesize)
Normal
========
Code:
/home/abc >ls -alr $ii_src_sqr/ftp_make.sqr                                    
-rwxrwxr-x    1 smt2uxb  smt2uxb       31223 May 26 15:04 /opt/smart/uat/eur/sources/sqr/ftp_make.sqr

Using AWK
===========
Code:
/home/abc >ls -alr $ii_src_sqr/ftp_make.sqr | awk -F/ '{print $NF}'            
ftp_make.sqr

How I can output as shown below (only paths blocked)
==================================
Code:
-rwxrwxr-x    1 smt2uxb  smt2uxb       31223 May 26 15:04 ftp_make.sqr


Last edited by Franklin52; 07-04-2011 at 03:20 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-04-2011
Piping your ls output through this should work:

Code:
awk '{n=split( $NF, a, "/" ); $NF=a[n]; print}'

The last field is split and n is assigned the number of fields. The last field is then assigned the last element of the array which is the basename, and then the record is printed.
This User Gave Thanks to agama For This Post:
# 3  
Old 07-04-2011
Code:
/home/abc >ls -alr $ii_src_sqr/ftp_make.sqr | sed "s:$ii_src_sqr/::"

# 4  
Old 07-04-2011
thanks it works
# 5  
Old 07-14-2011
blocking only path in ls command - with awk output bit scattered

just noticed
awk '{n=split( $NF, a, "/" ); $NF=a[n]; print}'
this gives output but which is bit scattered as shown below

-rwxrwxr-x 1 smt2uxb smt2uxb 27741 May 12 2010 ftp_make.sqr_repair
-rwxrwxr-x 1 smt2uxb smt2uxb 27264 May 12 2010 ftp_make.sqr_20080925
-rwxr-xr-x 1 smt2uxb smt2uxb 31064 May 16 16:55 ftp_make.sqr:3
-rwxrwxr-x 1 smt2uxb smt2uxb 28560 May 13 2010 ftp_make.sqr:2
-rwxrwxr-x 1 smt2uxb smt2uxb 28561 May 12 2010 ftp_make.sqr:1
-rwxrwxr-x 1 smt2uxb smt2uxb 31223 May 26 15:04 ftp_make.sqr
-rwxrwxr-x 1 smt2uxb smt2uxb 28560 May 12 2010 ftp_make.sat

can i make it tab separated and better readable ?
# 6  
Old 07-17-2011
The easiest way would be to substitute a tab character for each space. If you have spaces in filenames use the second example:

Code:
awk '{n=split( $NF, a, "/" ); $NF=a[n]; gsub( " +", "\t", $0); print }'

Code:
awk '{
   n=split( $NF, a, "/" );     # basname the path
   NF -= 1;                    # chop the last field
   gsub( " +", "\t", $0);      # replace blanks with tabs
   printf( "%s\t%s\n", $0, a[n] );    # print tab spaced line adding basname
}' input-file

This "breaks" if any field is wider than your tab stop.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

2. UNIX for Dummies Questions & Answers

Help with cp command using relative path?

I have a lab I am doing for a Linux Operating class. The question I am stumped on is "For the following questions, only use the cp command to copy files. You should currently be inside your lab07 directory. Create a subdirectory inside this directory called ones and copy (working ... (1 Reply)
Discussion started by: CodyMongrel
1 Replies

3. Programming

Which are blocking and non-blocking api's in sockets in C ?

among the below socket programming api's, please let me know which are blocking and non-blocking. socket accept bind listen write read close (2 Replies)
Discussion started by: VSSajjan
2 Replies

4. Red Hat

How to find the path of a command?

Hi guys. I want to know the path of a command. I tried "which" command also . But no luck. Please tell me how to find and update the correct path of the command. Here I'm unable to find the path of ext2online command # resize2fs /dev/vg01/lvora_backup resize2fs 1.39 (29-May-2006)... (3 Replies)
Discussion started by: vamshigvk475
3 Replies

5. Shell Programming and Scripting

No need path in output of LS command

hi, while i am placing the command. ls /app/callidus/rci_vst_p1/vst_fact_sms_cdr* I am getting the below ouput.. Output /app/callidus/rci_vst_p1/Inbound/vst_fact_sms_cdr_20101124.dat /app/callidus/rci_vst_p1/Inbound/vst_fact_sms_cdr_20101215.dat... (4 Replies)
Discussion started by: rsivasan
4 Replies

6. UNIX for Advanced & Expert Users

Blocking the ssh-keygen command

Hi All, I have a set of 100 servers , where users login through ssh, with a set of around 4-5 users. We have copied over the public keys to all the servers, for a passwordless authentication. Is it possible to block the ssh-keygen command for the users , so that the users that login do not... (5 Replies)
Discussion started by: nua7
5 Replies

7. Solaris

How to set path for a command

Hi all, I am trying ping command in SUN v240 server but it is not working but when i am using the full path /usr/sbin/ping <ip address> then it is working. how to set the path of ping command so that by simply typing ping <ip address> it should work ? Plz help me out:( (7 Replies)
Discussion started by: saurabh84g
7 Replies

8. UNIX for Dummies Questions & Answers

How to set a path for a command?

Hi, I install java at Fedora Core. So to run any java applications i have to write the complety path. For example, /usr/java/jre1.5.0_11/bin/java "javafile" I want to write only "java" but it said "command not found". How i fix this? Thank you very much Lakis (4 Replies)
Discussion started by: Lakis
4 Replies

9. Shell Programming and Scripting

running a command without having to provide the path

ok, i am aware of adding the directory where the files are located into the .profile file but the problem is, its not working for me. can someone please spell out how to properly edit these configuration files so i can run a command anywhere on the system without having to be in the... (2 Replies)
Discussion started by: Terrible
2 Replies

10. Shell Programming and Scripting

displaying the path in the command line

Hi all, Does anyone know how to ammend the .cshrc file in $HOME for your session to display the path as part of the command line? So that I dont need to keep on typing pwd to see where I am? thanks Ocelot (2 Replies)
Discussion started by: ocelot
2 Replies
Login or Register to Ask a Question