Here is the code I am using in my script:
cat log.txt | egrep -o "[0-9]{1,3}" >new.txt | sort new.txt | uniq >uniq.txt
I am essentially trying to find numbers within a file and list all of those numbers in a new file, then sort the new file, then create another file of only the unique numbers. This is for a school project and the professor said all 4 of the commands should be completed in a single line of code using pipes. The code does work, but not the first time. I can run the script and it gives the error below:
sort: cannot read: new.txt: no such file or directory
It does still create new.txt and uniq.txt though as I can see them when I ls. If I run the script again it will now work. If I remove the files and run it again it will once again give the error until I run it a second time. The last part of the script is supposed to delete those files which led me to discover this issue.
Any help would be greatly appreciated.