Data Science Specialization by E&ICT, IIT Roorkee for $159 | Expires inEnroll Now
A shell script is a file which contains the commands separated by a newline.
Let's create a script to do the sorting of the data:
Create a file using nano text editor:
The first line of a script should have "#!" followed by the name of the program to execute the script with. Since we are creating a shell script, we want it to be executed using bash. So, the first line of the program should be:
Add the command in the editor:
tr 'A-Z' 'a-z'| sed -E 's/[ \t]+/\n/g'|sed 's/[^0-9a-z]//g' | sort|uniq -c|sort -nr -S 50M
Save the file by pressing Ctrl+x and "y"
Now, make this file executable:
chmod +x wordcountscript.sh
Check if it is running:
cat /cxldata/big.txt | ./wordcountscript.sh | more
Please recall "./" means current directory and " | more" will show the result pagewise instead of causing too much scrolling.
Also, note that whatever is the input to the script is also passed to the programs executed in the script.
Taking you to the next exercise in seconds...