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
/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
/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)
-rwxrwxr-x 1 smt2uxb smt2uxb 31223 May 26 15:04 ftp_make.sqr
agama
July 4, 2011, 12:08am
2
Piping your ls output through this should work:
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.
Aia
July 4, 2011, 12:26am
3
/home/abc >ls -alr $ii_src_sqr/ftp_make.sqr | sed "s:$ii_src_sqr/::"
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 ?
agama
July 17, 2011, 1:11pm
6
The easiest way would be to substitute a tab character for each space. If you have spaces in filenames use the second example:
awk '{n=split( $NF, a, "/" ); $NF=a[n]; gsub( " +", "\t", $0); print }'
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.