Could it be possible to sort all of files in a folder and add z- to the name of the sorted file?
The names of the files to be sorted before the files are sorted
I don't see any way of sorting filenames to get the order you have specified for the filenames to be processed, and I don't see why it matters which of the files are sorted first. If you just wanted to sort these four files (or all files whose filename starts with AC- ), it would be a trivial task to do this using a standard shell.
Since you insist on using csh instead of bash or ksh or some other standard shell, I'll let someone else with more experience with more experience with csh syntax and semantics try to help you with a loop to do what you want.
It would help if you would show us what you have tried to solve this problem on your own. If you can code your own loop, the sort and mv or rm commands needed inside the loop won't vary much from shell to shell.
The filenames doesn't have to be sorted, only the files themselves need to be sorted and after sorting add z- to the beginning of the filename. It doesn't matter which of the files are sorted first. I have 2000 files in my folder. I only gave 4 examples of the filenames before.
So, you want to numerically sort the content of each file to create a new file with a prefix of z- . Is that correct?
You need a loop that uses all your file names and the processes them with something like:-
sort -bn "$inputfile" > "z-$inputfile"
I'm not so sure of the foreach syntax in csh. The flags -bn asks sort to ignore blank/whitespace and sort numerically - which I think is what you want.
A reply to rbatte1. Yes, you have understood everything correctly. But I'm getting a error report in my C Shell window when I'm trying to use your code:
If you were using a standards-conforming shell (such as bash or ksh ), you could use something like:
for inputfile in AC-*
do sort -n -o z-"$inputfile" "$inputfile" && rm "$inputfile"
done
Since you choose to use csh , it is up to you to translate this code to create a loop in csh and to only run the rm command after if verifies that the sort command completed successfully.
I don't have a file called inputfile. I tried to install bash to my pc but I didn't succeed, so I have no other option to use C Shell and Unix subsystems for Windows. Could somebody help me to make the codes that have been offered in this thread before suitable for C Shell?
Perhaps not, but you do *have* some (file that serves as) inputfile, no? It makes sense to call a variable holding the name of it "inputfile". Corollary advice: when the navigation system in your car tells you to "turn right" it doesn't mean you should rotate clockwise on your seat either.
bash is part of the SUA, so it should be already there when you install it (correctly). I suggest you get the installation of the SUA right first and only then start to worry about C shell - if it is still necessary at all, that is. Doing something wrong first and then patch it somehow to almost work is a sure way to disaster in the long run anyway, so it is better to correct that now better than later.
This simpler question of yours has been answered in post#9, albeit in bourne shell "language". You even had an attempt of a solution to a similar problem in csh "speak" in post#4.
You insist on a full blown csh solution (for not being able to use that bourne one) for two weeks now - chances are dwindling you'll get one unless you translate / create it yourself.
I can't understand why you steadfastly insist on using the C-shell. From your output:
/bin/csh
/usr/bin/csh # these two are C-shells
/bin/sh
/usr/bin/sh # these two are Bourne-shells, the ancestor of both bash and ksh
/bin/ksh
/usr/bin/ksh # these are Korn-shells, the preferable tool
/bin/tcsh # these are Tenex-C-shells, a more modern and matured
/usr/bin/tcsh # (but unfortunately non-standard) version of the C-shell
You could run most of the scripts suggested to you in ksh as well as in bash and even if you would insist on C-shell you should use tcsh instead of the original csh.
As bakunin has already implied, if you run the code I suggested in post #9 in this thread with ksh it should do exactly what you said you want to do. (You might note that in that post I said it would work with either bash or ksh .)
Depending on the vintage of sh on your system, that code might also work if you run it with sh or even rsh .
Hi! Thank you for your help! I really didn't know that I have the necessary shells in my pc since I'm relatively unexperienced. Now that I've found them evetything works great! Solution offered in post #9 works great in ksh! Thank you Don Cragun! This thread can be marked solved!