Question

I'm trying to make an alias in .alias file for tcsh. Alias is something like this :

alias do "grep -iE '<pattern>' <file> | awk '{if($2 < 0)print}'"

When i try to run the alias it give me following error :

awk: cmd. line:1: {if( < 0.0) print}
awk: cmd. line:1:      ^ parse error

Any idea why this would happen ? Thanks.

Was it helpful?

Solution

Give this a try. You need to escape the single quotes and don't use any double quotes.

alias do 'grep -iE '\''pattern'\'' filename | awk '\''{if ( $2 < 0 ) print}'\'''

OTHER TIPS

Well, to start with the command line you provide is gibberish:

$ alias do "grep -iE '' | awk '{if($2 < 0)print}'"
bash: alias: do: not found
bash: alias: grep -iE '' | awk '{if( < 0)print}': not found

If I correct it to what I think you mean, I see this:

$ alias do="grep -iE '' | awk '{if($2 < 0)print}'"
$ alias do
alias do='grep -iE '\'''\'' | awk '\''{if( < 0)print}'\'''

And with this we can see why you're getting a parse error. The $2 is being eaten by the shell before awk ever sees it. Try this instead:

$ alias do="grep -iE '' | awk '{if(\$2 < 0)print}'"
$ alias do
alias do='grep -iE '\'''\'' | awk '\''{if($2 < 0)print}'\'''

My guess is that at this point you won't be getting your parse errors any longer. (I can't speak for the rest of this, naturally, since I don't know what you're using as input.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top