-1

I want to convert the following command to a tcsh shell alias for reuse:

find uvm_template/ -type f -exec sed -i 's/CANDY/SE_IP/g' {} \;

I added to the alias file the following:

alias find_and_rep 'find $1 -type f -exec sed -i \'s/$2/$3/g\' {} \;'  

where $1 is the folder path, $2 the word to find, and $3 the word to replace.

When I execute source ~/.aliases to the alias file, I got the following error:

Unmatched '.

I tries also the following alias:

alias find_and_rep 'find $1 -exec sed -i "s/$2/$3/g" {} \;'

But when I execute the alias from the terminal I got the following:

find_and_rep uvm_template/ CAND SE_IP

find: paths must precede expression: uvm_template/
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
roaima
  • 107,089
  • 14
  • 139
  • 261
Sarti
  • 1
  • 1
  • I change the alias to alias find_and_rep 'find $1 -exec sed -i "s/$2/$3/g" {} \;' . Now I got the following error when I try to use as following: find_and_rep uvm_template/ CAND SE_IP find: paths must precede expression: uvm_template/ Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] – Sarti Aug 17 '23 at 13:30
  • Among the answers to the question that aviro linked to earlier (comment now deleted), there is [this answer](https://unix.stackexchange.com/a/457019/116858), which I belive applies to your issue (`csh` and `tcsh` uses the same `alias` syntax). I don't know if it solves your issue as I'm not a `tcsh` or `csh` user myself. – Kusalananda Aug 17 '23 at 13:31
  • If you have any new problem, please [edit] your question and add your updates. Make sure to use code formatting whenever you paste something from your console (like I did when I edited your question). Anyway, check the comment from Kusalananda, this might help you with the issue. – aviro Aug 17 '23 at 13:47
  • This whole question has been asked before and had gathered lots of comments, but has now been deleted. – Panki Aug 17 '23 at 14:55
  • @Panki I removed the comments that assumed that the user was trying to construct a bash alias, along with the comments that asked about what shell the user was using. The remaining comments were deleted by their respective authors it seems. – Kusalananda Aug 17 '23 at 15:59

0 Answers0