Questions about using shell variables in awk

Source: Internet
Author: User
Questions about using shell variables in awk

Author: swysn published at: 2002/03/22 05:01 pm

[This post was last edited by Valentine at]

2002/01/01
1312 32132 AA 32132131

#! /Bin/sh
Echo "Enter :"
Read key
Cat TT | awk '{If (prev = "$ key") print; Prev = $1}

The above content
If I lose: 2002/01/01
No result output!
Again wrong?

Related Comments of this article:
This article has 11 related comments as follows: (you can post comments here)
Valentine Posted on: 2002/03/23 AM
[This post was last edited by Valentine at]

You have a good idea, but the variables cannot be used in awk. You can simply change them to the following form.
Echo "Enter :"
Read key
Export key
Cat filename | awk '{If (prev = environ ["key"]) print; Prev = $1 }'

You can also:
Echo "Enter :"
Read key
Cat filename | awk '{If (prev = "' $ key'") print; Prev = $1 }'

There are many other methods. I will not list them one by one. You can view the awk-related posts.

 
Pdyhww Posted on:
Moderator. Is there any other way to use shell variables in awk? Except for:
Export value
A = environ ['key']
 
Binary Posted on:
-V option can also specify a variable
This question has been discussed before. Search for it.
 
Dedicated for victory Posted on: 2002/11/06
I will use the shell variable to pass it to awk, especially when the passed variable features (> 399 bytes !!!
Export A = "hello"
Awk 'in in {"Echo $ A" | Getline X; print X ;}'
 
Masher Posted on: 2002/11/07 pm
Var1 = ABCD
Var2 = efgh
Echo "" | awk-V First = $ var1-V Second = $ var2 '{print first "" Second }'

[Display] abcdefgh

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.