Results 1 to 4 of 4

Thread: Awk confusion with regular expressions

  1. #1
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    6,516
    Distro
    Lubuntu 14.04 Trusty Tahr

    Awk confusion with regular expressions

    Code:
    [09:38 PM] ~ $ awk '/bin/sh/ { print }' /etc/passwd
    awk: cmd. line:1: /bin/sh/ { print }
    awk: cmd. line:1:          ^ syntax error
    [09:39 PM] ~ $ awk '/bin\/sh/ { print }' /etc/passwd
    daemon:x:1:1:daemon:/usr/sbin:/bin/sh
    bin:x:2:2:bin:/bin:/bin/sh
    sys:x:3:3:sys:/dev:/bin/sh
    games:x:5:60:games:/usr/games:/bin/sh
    man:x:6:12:man:/var/cache/man:/bin/sh
    lp:x:7:7:lp:/var/spool/lpd:/bin/sh
    mail:x:8:8:mail:/var/mail:/bin/sh
    news:x:9:9:news:/var/spool/news:/bin/sh
    uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
    proxy:x:13:13:proxy:/bin:/bin/sh
    www-data:x:33:33:www-data:/var/www:/bin/sh
    backup:x:34:34:backup:/var/backups:/bin/sh
    list:x:38:38:Mailing List Manager:/var/list:/bin/sh
    irc:x:39:39:ircd:/var/run/ircd:/bin/sh
    gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
    nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
    libuuid:x:100:101::/var/lib/libuuid:/bin/sh
    [09:39 PM] ~ $ awk '/\/bin\/sh\// { print }' /etc/passwd
    [09:40 PM] ~ $
    I tried three awk commands (in bold) using /etc/passwd as the input file. Only the second command worked. Why did the third command not work? Instead, I just got back the prompt implying that there was nothing for awk to print.
    de gustibus et coloribus non est disputandum -- Wiktionary

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,439
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Awk confusion with regular expressions

    because there is no /bin/sh/
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    6,516
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Awk confusion with regular expressions

    Quote Originally Posted by Vaphell View Post
    because there is no /bin/sh/
    Kicks self ... hard
    de gustibus et coloribus non est disputandum -- Wiktionary

  4. #4
    Join Date
    Feb 2007
    Location
    West Hills CA
    Beans
    8,959
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Awk confusion with regular expressions

    You could make one.
    -------------------------------------
    Oooh Shiny: PopularPages

    Unumquodque potest reparantur. Patientia sit virtus.

Bookmarks

Posting Permissions

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