Sponsored Content
Full Discussion: Creating table in Unix
Top Forums Shell Programming and Scripting Creating table in Unix Post 302357942 by Scott on Thursday 1st of October 2009 03:26:40 AM
Old 10-01-2009
You can use awk to rearange the fields from an ls command and add some logic to determine the type of file.

For example:
Code:
ls -al | awk '
  /^total/ { next }
  {
    TYPE = "regular file"
    if ($1 ~ /^d/)
      TYPE = "directory"
    else if ($NF ~ /^\./)
      TYPE = "hidden file"
    else if ($1 ~ /^b/)
      TYPE = "block device"
    else if ($1 ~ /^p/)
      TYPE = "pipe"
 
    printf( "%-30s %14s %10d %s\n",  $NF, $1, $5, TYPE)
  }
'
.                                  drwxr-xr-x       4096 directory
..                                 drwxr-xr-x       4096 directory
file1                              -rw-r--r--        141 regular file
file2                              -rw-r--r--         30 regular file
my_logfile                         -rw-r--r--          6 regular file
myPipe                             prw-r--r--          0 pipe
T                                  -rwx------        185 regular file
tmp                                drwxr-xr-x       4096 directory
tmp2                               drwxr-xr-x       4096 directory
.x                                 -rw-r--r--          0 hidden file
Y                                  -rwx------        321 regular file

Which OS / Shell are you using? It's not clear from your permission fields how you determine what's what. (i.e. a file with ---------- does not respresent a hidden file)

Last edited by Scott; 10-01-2009 at 07:54 AM.. Reason: fixed paste error: closing apostrophie in the wrong place
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Creating a hash table using shell script

Hi, For one of my programs, I need to have a hashtable as in Perl. Unfortunately shell doesnt provide any variable like hash. Is there anyway/trick, I could implement a hash in shell (using shell scripts/sed/awk). JP (2 Replies)
Discussion started by: jyotipg
2 Replies

2. Programming

Creating a Hash Table

Dear Friends, I want to create a hash table using the standard Glib header (if possible) so that I can store a structure and keep the hash key(search key) based on a string. Any example code would be great since I am not able to get the main idea. best regards Skull (4 Replies)
Discussion started by: callmetheskull
4 Replies

3. UNIX for Dummies Questions & Answers

Creating a table (graphic not database)

Hi, I want to create a table on our unix box that allows the user to tab through it and select certain option by putting an asterix or similair into it. e.g. -------------- |Start App | | |Stop App |*| etc... Can this be done using a script (never seen any graphics options in ksh, but... (2 Replies)
Discussion started by: dlam
2 Replies

4. Programming

Creating a table like format with rows and columns

I have few files which have two columns in each. like e2 1 1 2694 2 4 2485 3 2 2098 5 1 2079 6 5 2022 9 4 1734 11 5 1585 13 2 1461 18 1 1092 21 2 1019 24 1 915 25 3 907 27 1 891 28 3 890 34 1 748 39 1 700 (1 Reply)
Discussion started by: kamuju
1 Replies

5. Shell Programming and Scripting

Creating a table

I have a file like below Iter 1: Best Model = 10.0 12.0 13.0 17.0 23.3 78.7 Iter 2: Best Model = 10.0 20.0 30.0 40.0 50.0 60.0 Iter 3: Best Model = 27.3 46.3 84.5 23.0 34.5 35.4 etc I want to use a scipts using csh or awk to select the iteration number and show the numbers in a table... (2 Replies)
Discussion started by: kristinu
2 Replies

6. Web Development

MYSQL: Creating Dynamic Table Names 5.1

Hey everyone. Thanks for looking at this. I'm trying to create a table with the dynamic name of TableName + today's date. My variables are all happily created but the system chokes when I try to create the new table name example: Set @BFBW = CONCAT("BFBW", CURDATE()); Select @BFBW; ... (2 Replies)
Discussion started by: Astrocloud
2 Replies

7. UNIX for Dummies Questions & Answers

Creating a condensed table from a pre-existing table in putty

Hello, I'm working with putty on Windows 7 professional and I'd like to know if there's a way to gather specific lines from a pre-existing table and make a new table with that information. More specifically, I'd like the program to look at a specific column, say column N, and see if any of the... (5 Replies)
Discussion started by: Deedee393
5 Replies

8. UNIX for Advanced & Expert Users

Insert Command Creating Table Locking Problem

Hi, i have a java based tool which does insert operation in a TABLE, and in parallel the same table is used by my C++ code which does select Query. the Table will be always busy, but sometimes the table is getting locked when i try to make an insert, am bit confused whether the lock is... (9 Replies)
Discussion started by: senkerth
9 Replies

9. Shell Programming and Scripting

Creating html table from data in file

Hi. I need to create html table from file which contains data. No awk please :) In example, ->cat file num1 num2 num3 23 3 5 2 3 4 (between numbers and words single TAB). after running mycode i need to get (heading is the first line): <table>... (2 Replies)
Discussion started by: Manu1234567
2 Replies
cdsuf(1)						      General Commands Manual							  cdsuf(1)

NAME
cdsuf - read the System Use Fields from a System Use Area SYNOPSIS
cdsuf [-s number] [-b] file OPTIONS
The following options are available: Specifies the File Section for the System Use Area to be read. The numbering starts with one. If this option is omitted the last File Section of that file is assumed. Copies all of the System Use Fields of the System Use Area from the CD- ROM to standard output in binary format. The name of any file or directory within the CD-ROM file hierarchy. DESCRIPTION
This command is used to access the System Use Fields of the System Use Area associated with a File Section of a file or directory on a Rock Ridge formatted CD-ROM and to list its contents on standard output, following any Continuation Fields that may be present. The output is formatted in the form of a table that contains an entry for each System Use Field in the System Use Area as recorded on the CD-ROM. Each table entry has the fields Signature, Length, Version, and Data as specified in the System Use Sharing Protocol. If the -b option is used, the contents of the full System Use Area are written to standard output in binary format as it is recorded on the CD-ROM. RESTRICTIONS
The user must have read permission for file to execute the command successfully. EXIT STATUS
The following exit values are returned: Successful completion. File not found, file is not a file or directory within a CD-ROM file hier- archy, or access denied. File Section indicated by -s does not exist. File Section indicated by -s has no System Use Area. SEE ALSO
cd_suf(3) cdsuf(1)
All times are GMT -4. The time now is 05:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy