Find the answer to your Linux question:
Results 1 to 4 of 4
Hi All, this code, from my Shell Programming book is troubling me. What does $1 !- /total/ do here..? I understand the rest of it. $ ls -l | awk ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2004
    Location
    Tokyo
    Posts
    24

    What does $1 !- /total/ do here..?


    Hi All,

    this code, from my Shell Programming book is troubling me. What does $1 !- /total/ do here..? I understand the rest of it.

    $ ls -l | awk `$1 !- /total/ { printf "%-32s %s\n" ,$9,$5 ; } `

    $9= File names
    $5=File size

  2. #2
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,790
    the $1 (iirc) is the first argument passed to the shell script, so if u ran:
    Code:
    ./shellscript.sh hello
    $1 would be equal to 'hello'.
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  3. #3
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    You've put backticks surrounding the awk arguments. If they should be single quotes, the $1 isn't a shell variable, it'll be the first field in the line that awk is matching. What that will do is match every line whose first field is not the string "total", and print the 9th and 5th arguments of those lines. It's basically printing out each line from ls -l but suppressing the total line.

    The reason the pattern isn't used on its own (awk /total/ { print ...}) is to guard against filenames containing the string "total".

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Nov 2004
    Location
    Tokyo
    Posts
    24
    Hi All,

    ah, my error there. I thought they were back ticks, as opposed to actually being single quotes. The book didn't explain the code's use of $1 1- /total/. It makes sense now.

Posting Permissions

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