You are Here:
Linux Lite 6.6 FINAL Released - Support for 22 Languages Added - See Release Announcement Section



Cat ate my homework

Author (Read 14497 times)

0 Members and 2 Guests are viewing this topic.

Re: Cat ate my homework
« Reply #3 on: October 15, 2018, 10:40:48 AM »
 

Shanti

  • New to Forums
  • *
  • 16
    Posts
  • Reputation: 14
  • Linux Lite Member
    • View Profile

  • CPU: Core i5 vPro

  • MEMORY: 16Gb
@bitsnpcs interesting thank you.
 

Re: Cat ate my homework
« Reply #2 on: October 13, 2018, 10:15:52 AM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x
Did the cat eat your homework , or was it the dog, or you spilled beer on it ?
Add your own version in the replies :)
 

Cat ate my homework
« Reply #1 on: October 13, 2018, 12:47:49 AM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Reputation: 305
    • View Profile
    • Try to Grow

  • Kernel: 4.x
Hello,

I made this up as an exercise to do a combined practice for some recent commands I learned in the first few pages of chapter 20, and recent chapters. I thought it might give other beginners some ideas of how to play about with commands they learn and make some exercises for practice.





Here we use cat command to create a text file in the home directory using the command line.
Also learning about using return/enter key to end the file, and then Ctrl D on the new line to exit editing .txt file back to the prompt.
Then using cat in the way learned in earlier chapter (6) of The Linux Command Line book to display the contents of the (loyal) hungry-cat.txt file on the command line.
Then using the find command to find our homework.txt file on the computer, and pipe command, then using cat to merge homework.txt contents and advice.txt and save the merge in the file named busted.txt.
Then again using cat, this time to display the contents of the merged file, to check it merged the two file contents, the first line of busted.txt appearing after the merge is the text from inside the homework.txt file and the rest of busted.txt being the text inside the advice.txt file, the busted.txt is an empty text file to begin with with no text inside it.
I got it wrong a few times but it was good practice using cat.

Cat seems a straight forward way to make .txt files from the command line, useful for a variety of things, examples given of uses were documents, web pages (HTML, XML) , scripts.

Edit -
To replicate the results as shown you need to make all the text files used, using cat in the terminal is a good practice for this.
If made using leafpad you may notice (as I did with the first 1 I tried) it appears with your username and prompt on the same line as the last line of text as you need to use the enter key to end a file with a new line then close it using the Ctrl D for the prompt to appear on its own new line, the book explains about ending the line using enter, but not what happens if you don't, such as when using leafpad, so this part was self learning by trying, and as it is likely to display this way with some leafpad files it is why I share info about what I noticed. So if you use cat to open a leafpad file and your prompt is not where you expect it to be we know why this is so, pressing enter key will move the prompt to a new line in its usual place.

So this is why it was a good practice for remembering the correct way to make the txt files using cat in the command line, and to close and end them properly using cat on the command line.
Which in the book it explains the difference in how MS DOS and Linux end lines in a different way using a different ASCII numbering, and the importance of spaces and end of lines characters even when they may not be visible (they can be made to be visible as code, which it also shows how to do) , this explains why some files created on windows may appear differently in Linux, it says that later in the chapter it will show ways to convert MS file formatting and end of lines to Unix/Linux format so it is more useful to us, which will also be a useful thing to learn. Also it will show how to make Linux formatting in to MS formatting.
So in the few pages of the chapter 20 used so far, it covers quite a lot of new ideas to me , and maybe other learners too, I needed practice to retain this info.

Looking at it it reminds me of a Python exercise to make a text based game which is run in the terminal , it showed examples of such games from the past, as the options and possible answers are stored as variables. So I think more advanced users can do something like this and make a text based game using the command line.
Where each answer is a link to a text file that is then called using cat, run as part of a script showing an "alias" text in the game to hide the commands from the player, where the alias fits in to the game text/scenario.
There are likely some other better ways but at this stage it is how I imagine that could be done.
That way the .txt files would be sort of like a tree as a map/chart with the player choices linking to different branches/routes.
I am not really in to games but I know many are, and I see how they can be used as a good way of learning commands as more of them would need to be used, and learned, in such a type of tutorial by the maker/s.
« Last Edit: October 13, 2018, 10:31:34 AM by bitsnpcs »
 

 

-->
X Close Ad

Linux Lite 6.6 FINAL Released - Support for 22 Languages Added - See Release Announcement Section