Azazia Software Knowledgebase
Search:     Advanced search
Browse by category:
Contact Us

Using Awk to display a directory listing on files with spaces until the end of line

Add comment
Views: 581
Votes: 0
Comments: 0
Posted: 18 Nov, 2009
by: Patridge B.
Updated: 18 Nov, 2009
by: Patridge B.
There are situations where when performing an ls -Al displays files with spaces.
--------------------------------------------------------------------------------------------
bash-3.00# ls -al
total 819568
drwxrwxrwx   2 apache   www         8192 Nov 17 10:05 .
drwxrwxrwx 3428 apache   www       122880 Nov 18 11:30 ..
-rwxrwxrwx   1 apache   www      86648513 Nov 16 17:51 23568_111609_hdcp.20091116.1751.tgz
-rwxrwxrwx   1 apache   www      144209996 Nov 17 10:00 SELRST XRC Trace FC Port(1,1,1).trc
-rwxrwxrwx   1 apache   www      35514812 Nov 17 10:01 SELRST XRC Trace FC Port(1,1,2).trc
-rwxrwxrwx   1 apache   www      1048852 Nov 17 10:01 SELRST XRC Trace FC Port(1,1,3).trc
-rwxrwxrwx   1 apache   www      1048852 Nov 17 10:01 SELRST XRC Trace FC Port(1,1,4).trc
-rwxrwxrwx   1 apache   www      116827584 Nov 17 10:04 SELRST XRC Trace FC Port(1,3,1).trc
-rwxrwxrwx   1 apache   www      31989256 Nov 17 10:05 SELRST XRC Trace FC Port(1,3,2).trc
-rwxrwxrwx   1 apache   www      1048852 Nov 17 10:05 SELRST XRC Trace FC Port(1,3,3).trc
-rwxrwxrwx   1 apache   www      1048852 Nov 17 10:05 SELRST XRC Trace FC Port(1,3,4).trc
-rwxrwxrwx   1 apache   www          776 Nov 17 10:05 SELRST XRC Trace.tgp
--------------------------------------------------------------------------------------------

To display the filename, a following does not work
#ls -Al |awk '{print $9}'

because it will display part of the filename:
--------------------------------------------------------------------------------------------
bash-3.00# ls -Al |awk '{print $9}'
23568_111609_hdcp.20091116.1751.tgz
SELRST
SELRST
SELRST
SELRST
SELRST
SELRST
SELRST
SELRST
SELRST
--------------------------------------------------------------------------------------------

To display the full filename until the end of line you need to do the following:


--------------------------------------------------------------------------------------------
bash-3.00# ls -Al |awk '{print substr($0, index($0,$9)) }'
total 819296
23568_111609_hdcp.20091116.1751.tgz
SELRST XRC Trace FC Port(1,1,1).trc
SELRST XRC Trace FC Port(1,1,2).trc
SELRST XRC Trace FC Port(1,1,3).trc
SELRST XRC Trace FC Port(1,1,4).trc
SELRST XRC Trace FC Port(1,3,1).trc
SELRST XRC Trace FC Port(1,3,2).trc
SELRST XRC Trace FC Port(1,3,3).trc
SELRST XRC Trace FC Port(1,3,4).trc
SELRST XRC Trace.tgp
--------------------------------------------------------------------------------------------
Others in this Category
document VI editor Backup (VIB) Utility
document E:Lists directory /var/lib/apt/lists/partial is missing.
document Regular Expression to Escape all Illegal (non alphanumeric) Characters Except a space
document Quick One liners to test a string whether or not it is an Integer, Alphanumeric, or Character
document UNIX Command Line way to convert HEX ascii codes to Text
document Restoring the cursors last position in the VI (VIM) editor
document Postfix/Sendmail Errors: NOQUEUE: reject: RCPT .... Relay access denied DSN: Service unavailable
document Display path, user name, and host name next to the cursor in the .bashrc or .bash_profile
document Little script to make process searching easier
document Create an SFTP account that will restrict the user only to their destination home directory so they cannot change directory (cd) or view any other files outside of that directory.
document Recompile apache2 to support LDAP on Solaris 10
document SVN Solaris 10: ld: fatal: Symbol referencing errors. No output written to .libs/svn
document SVN Solaris 10: ld.so.1: svnversion: fatal: libssl.so.0.9.8: open failed: No such file or directory
document Solaris 10: commit failed: svn: Couldn't perform atomic initialization
document Creating a UNIX sparse file on an Isilon system



RSS