开发者

awk parse error on '<' operator

开发者 https://www.devze.com 2023-01-23 14:13 出处:网络
I\'m trying to make an alias in .alias file for tcsh. Alias is something like this : alias do \"grep -iE \'开发者_如何学Go<pattern>\' <file> | awk \'{if($2 < 0)print}\'\"

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

alias do "grep -iE '开发者_如何学Go<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.


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}'\'''


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号