Find the answer to your Linux question:
Results 1 to 5 of 5
Using Bourne shell, is there an easy way to get the string in a specified field of output? Something like this: Code: field 3 `ls -l $file` to get the ...
  1. #1
    Just Joined!
    Join Date
    Jul 2006
    Posts
    17

    Bourne Scripting Question

    Using Bourne shell, is there an easy way to get the string in a specified field of output?

    Something like this:

    Code:
    field 3 `ls -l $file`
    to get the owner of $file.

    Or

    Code:
    field 1 `cksum $file`
    to get only the checksum of $file.

    Or is there a safer way of getting the owner, cksum, and size of a file?

    Thanks.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Enter this at the shell prompt:
    Code:
    man cut
    and all will be revealed.

    If you do not have man pages installed on your system, google this:
    Code:
    man cut linux
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Jul 2006
    Posts
    17
    Thank you!

  4. #4
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    # a=`cksum file`
    # set -- $a
    # echo $1
    445709364

  5. #5
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by ldb88 View Post
    Using Bourne shell, is there an easy way to get the string in a specified field of output?

    Something like this:

    Code:
    field 3 `ls -l $file`
    to get the owner of $file.

    Or

    Code:
    field 1 `cksum $file`
    to get only the checksum of $file.

    Or is there a safer way of getting the owner, cksum, and size of a file?

    Thanks.
    The most similar thing to this that you wrote above, under my point of view, would be to use awk.

    Code:
    $ ls -l /etc/make.conf | awk '{ print $3 }'
    root
    I don't usually advice this though. And *nix has a command for this stuff anyway:

    Code:
    $ stat -c %U /etc/make.conf
    root
    An interesting man page to read, by the way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...