The ability to do this on one line in csh/tcsh is somewhat limited, as pointed out on this page:
Unfortunately, the csh does not allow the use of ';' in place of new-line characters at the start of a loop, such as:
foreach fn ( * ) ; file $fn ; end
<- This doesn't work
In this case, it is necessary to resort to more indirect methods.
alias check_ultras '(echo "foreach host ( tlsc0{1,2,3,4} ) " ; echo "echo :::: "\$"host :::: " ; echo "rsh "\$"host top -n -d1 7" ; echo "end" ) | csh'
echo "while ( 1 ) \n" "xset "{,-}"led 2; sleep 1 \n" end | csh -f
So in your case, you could do something like:
alias change_files '(echo "set n=0; foreach txt ( *_*.txt )"; echo "sed 's/_/-/g' "\$"txt"; echo "@ n ++"; echo "end"; echo "echo You changed "\$"n files) | csh'
change_files
(or, to avoid creating the separate alias:)
'(echo "set n=0; foreach txt ( *_*.txt )"; echo "sed 's/_/-/g' "\$"txt"; echo "@ n ++"; echo "end"; echo "echo You changed "\$"n files) | csh'
But you could probably do this easier another way. What are you actually trying to do -- rename the files, or change the contents of those files?