Here are the contents of a file:
one two three
four five six
And here is my alias
alias testawk "awk '{print $2}' file"
This is what I get:
> testawk
one two three
four five six
But when I give this command, then I get what I want:
> awk '{print $2}' file
two
five
How do I escape the field specifier in the alias? NOTE: I'm using csh
Variables are used to store any value temporary in any programming language. Defining the variable in awk command is similar to bash scripting language and it works like bash when the shell variable is used with a single quote and double quote. Awk command has many built-in variables for various purposes.
NF is a predefined variable whose value is the number of fields in the current record. awk automatically updates the value of NF each time it reads a record. No matter how many fields there are, the last field in a record can be represented by $NF .
The awk variables $1 or $2 through $nn represent the fields of each record and should not be confused with shell variables that use the same style of names. Inside an awk script $1 refers to field 1 of a record; $2 to field 2 of a record.
Passing variable as input & storing output in other variable var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results...
Wrap the alias w/ '
and use '\''
for the embedded '
.
alias testawk 'awk '\''{print $2}'\'' file'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With