10

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

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
B Johnson
  • 2,408
  • 3
  • 20
  • 32

1 Answers1

18

Wrap the alias w/ ' and use '\'' for the embedded '.

alias testawk 'awk '\''{print $2}'\'' file'
Louis Marascio
  • 2,629
  • 24
  • 28