-2

How do I create an alias for awk command in

awk '{$1="";$2="";$3="";$4="";$5="";print}'

in tcshrc ?

I tried like this:

alias crd='awk '\''{$1=\"\";$2=\"\";$3=\"\";$4=\"\";$5=\"\";print}'\'''

but did not work

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 2
    clean approch would be to create a function in your rc file.Dont go with alias – P.... Jul 24 '18 at 12:28
  • 4
    `did not work` is the worst possible problem description. `Dear mechanic, my car did not work - now tell me how to fix it`. – Ed Morton Jul 24 '18 at 12:29
  • Possible duplicate of [How to escape single quotes within single quoted strings?](https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings) – tripleee Jul 24 '18 at 12:32
  • 1
    @PS. .. a function would certainly be the approach in bash, but **tcsh** is a little more limited in that regard -- as well as being a bit more flexible for aliases. – ghoti Jul 24 '18 at 12:32
  • @ghoti never got chance to work on tcsh,thanks for info :) – P.... Jul 24 '18 at 12:34
  • Sorry, didn't notice this had [tag:tcsh]; you want a different duplicate, but this is almost certainly a duplicate still. – tripleee Jul 24 '18 at 12:34
  • @tripleee this might be one: https://stackoverflow.com/questions/382734/escaping-double-quotes-with-tcsh-alias – Sundeep Jul 24 '18 at 12:35
  • Depends if the problem is a syntax error or summoning Cthulhu or something in between. So far the OP isn't sharing... – Ed Morton Jul 24 '18 at 12:35
  • 1
    I agree with needing more information from OP, but I would suggest holding back downvotes and give OP a chance to edit the question... – Sundeep Jul 24 '18 at 12:39
  • 1
    @Sundeep .. I agree with giving the OP a chance. In addition, we should be cognizant that while the OP is having quoting challenges, the actual solution to hid underlying problem may be more along the lines of [this](https://stackoverflow.com/q/10693608/1072112). If we treat the question as a programming one rather than a shell syntax one, we probably do SO a favour in the long run. :) – ghoti Jul 24 '18 at 12:49

1 Answers1

2

Your problem may just be that your backslash finger is too heavy. Double quotes inside the single quoted string do not need to be escaped unless they're part of a double-quoted string that is inside the single quotes.

But it may also be that you're confusing the bash alias command with the tcsh alias command. Bash notation looks like:

alias thing=command

whereas tcsh looks like:

alias thing command

Note the subtle difference. :-)

The following generates no errors for me:

% alias crd 'awk '\''{$1="";$2="";$3="";$4="";$5="";print}'\'''

The alias even seems to be functional:

% seq -s\  1 8 | crd
     6 7 8

You might also find this answer useful, if your goal is actually to remove columns rather than just nullify content.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
ghoti
  • 45,319
  • 8
  • 65
  • 104