Find the answer to your Linux question:
Results 1 to 7 of 7
Hi everyone, my question is quite simple, could you tell me what this small part of code means? cat $File | grep .Vault | sed "s/ *$//" | \ awk ...
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    3

    Help with awk

    Hi everyone,
    my question is quite simple, could you tell me what this small part of code means?

    cat $File | grep .Vault | sed "s/ *$//" | \
    awk -vvowner=$vowner \
    'BEGIN
    {
    ....
    }

  2. #2
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    the sed portion is "greedy match 0 or more" (that's the *) $ means the end of the string. Looks like it says grab whatever is at the end and get rid of it, since is a substitution-mode regex. that output gets sent to awk where it makes a variable named vowner and is assigned the value of $vowner, which I would assume is defined previously in the script.

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Posts
    3
    Thanks for your answer.

    But what im wondering is how the awk will be executed.

    "It looks for a line in the file with .Vault", the spaces at the end of the line are erased. And it sends the line in the awk and because any delimiters are defined, the awk will do something for each character in the line."

    That's it?

  4. #4
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    awk will do whatever is passed to it from sed, what exactly awk will do is defined after the BEGIN inside those brackets.

  5. #5
    Just Joined!
    Join Date
    Feb 2010
    Posts
    3
    You're absolutely right, what I meant to say is if in the BEGIN i write " echo {1}"
    and I had the line "hello my friend.Vault". What result shoult I get?

    Thank you for your help.

  6. #6
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by kidam! View Post
    You're absolutely right, what I meant to say is if in the BEGIN i write " echo {1}"
    and I had the line "hello my friend.Vault". What result shoult I get?

    Thank you for your help.
    Why don't you run the script and see for yourself...
    Make mine Arch Linux

  7. #7
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    if the result from sed is:

    Vault blah 2 exit

    Code:
    print $1
    would yield Vault, as its the first string in the input of awk

Posting Permissions

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