shell-genomics
shell-genomics copied to clipboard
Episode 6. Addition of a "cut" command to remove line numbers in history
In the section for documenting your work, the following code is run
history | tail -n 7
The output is
651 mkdir dc_workshop 652 mkdir dc_workshop/docs 653 mkdir dc_workshop/data 654 mkdir dc_workshop/results 655 ls -R 656 history 657 history | tail -n 7
The next step in the lesson is to redirect this output to an executable script so that the commands can be re-executed. However, the bash will return a command not found error because of the line numbers. This is a good opportunity to introduce the cut command by applying it to remove the line numbers. The command will be:
history | tail -n 7 | cut -d " " -f4-
The output
mkdir dc_workshop mkdir dc_workshop/docs mkdir dc_workshop/data mkdir dc_workshop/results ls -R history history | tail -n 7 history | tail -n 7 | cut -d " " -f 4-
I also noticed this issue. If introducing another command would add too much content, another way to address this would be to edit the instructions to read:
Next, remove any lines of the history that are not relevant by navigating to those lines and using your delete key. Also remove the line numbers preceding each command. Save your file and close nano.
Hi @ckigenk and @awnorowski - apologies for not getting back to you sooner, and thanks for your suggestions!
cut is a very useful command, but the main course is already quite long and I'm not sure there's time to cover it properly. Also, the cut command is currently introduced in an optional extra lesson, so we should probably avoid duplicating too much content.
If introducing another command would add too much content, another way to address this would be to edit the instructions to read:
Next, remove any lines of the history that are not relevant by navigating to those lines and using your delete key. Also remove the line numbers preceding each command. Save your file and close nano.
I think this is a good compromise - it makes explicit what learners need to do to ensure their script will work