tr – First Use

tr – Translate of Delete. This is the first time i am using this command and it was pretty nice. Used the gui repalce functionality on text editors so far and, sed recently. But this seems pretty nice.

tr 'abc' 'xyz' will replace the occurence of abc with xyz. Takes input from the standard input. Meaning if you run this command and type something in and press enter. You will see the results down below. Common use is to cat and pipeline the content though.

Sed – Quick Reference

Another personal reference

Two basic forms of use.
sed [-n] [-e] 'command(s)' files
sed [-n] -f scriptfile files

First one uses inline commands. The second one uses a script file. A command like delete or print can be executed based on an address/line range or a pattern. Lets look at the commands themselves in no particular order just to recollect things. All concepts are mixed and mashed.

  1. p stands for print and it prints the lines that are specified. ‘1p’ will print the first line.
  2. '1,5 p' will print the lines from one to five.
  3. '2, +3 p' will print line 2 and the next 3 lines as well.
  4. '2, ~4 p' will print line 2 and every fourth line from that. Meaning, 2, 6, 10, 14, 18, 22…
  5. Address and Pattern matching can be used together.'/hello/, 5 p' looks for the line that has ‘hello’ and then prints five lines that follow it.
  6. '/hello/, $ p' prints from the line that has the first occurence of hello till the end
  7. '/pattern1/ /pattern2/ p' prints all the lines that contains pattern 1 upto the line that contains pattern 2.
  8. d is for deleting a line. Similar to p, for printing.
  9. w can be used to write to a file after filtering some lines. Or with no filters at all, which would make it work like a cp command.
  10. 'w newfile' will make a copy of the target file into the new file
  11. '2,5 w newfile' will just write the lines 2 to 5 of the target file to the new file. Pattern matching can also be used instead of Address matching.
  12. a can be used to append a line to a file.
  13. '4 a text to be appended' appends the text to be appended to the file after line 4.
  14. c can be used for replacing or changing patterns or lines.
  15. '4 c text line to be replaced' will replace the fourth line with the text line to be replaced. Multiple lines can be replaced with single lines as well.
  16. i stands for insert.
  17. y for translate.
  18. Syntax for y [address1[,address2]]y/list-1/list-2/.
  19. [address1[,address2]]l shows hidden characters
  20. [address]q [value] for quit
  21. [address]r file read and insert contents of file into address of the target file specified
  22. [address1[,address2]]e [command] execute bash command on the address
  23. [address1[,address2]]s/pattern/replacement/[flags] substitute command
  24. 's/Paulo Coelho/PAULO COELHO/w junk.txt' replace and write to new file

More to be added to this post.

xargs – possible uses

Xargs is one of those commands I have never used. Recently I was looking into how I can use them in the scripts I use on a daily basis.

Here are some. These are for personal references. If you find it useful. Please go ahead and use them.

  1. xargs, was actually used to get over the limitations of the number of arguments that a certain command can handle. But then it has been used for other purposes as well now I guess.
  2. ls somefilepattern | xargs can convert the list that would have been displayed vertically into a list that is displayed on a single line seperated by spaces, since it is actually converting it to an argument list for some command. This can be a really useful oneliner.
  3. When you want it to act as an argument list for some command then ls somefilepattern | xargs command will do. What this is doing is that it is taking a list of those files, converting them into an argument list and passing it to the command. Good!
  4. A good derivation of the last two points is that it can be used with commands like the cut command to get some vertical list, which can then be passed on to a command or just convert it to a oneline list. Ex: ls * | cut -d "." -f1 | xargs

They say it is mostly used with find command but then I cannot relate to those uses.

Executing Shell commands inside Vim

Shell commands can be executed inside vim. You can use ! after the : and type in your command. You need to know just one more thing and you can be off. The current file is specified by the % character. For for example, if you want to find the word count of the current file, type in, :! wc %. If you want for example to execute the script you are writing then :! bash %, will run the current bash script you are writing. The display will momentarily go out of vim to display the results but will be back to vim as soon as you hit Enter.

Vim – Quick Start

Although I am typing this blog post on vim with html. I sometimes do not use Vim. I am all around the place with Atom sometimes, or Gedit or pluma or Visual Studio Code sometimes. But then I come back to vim for the simplicity of things. When I do, i sometimes forget what i need to know to get back to my old Vim state. This one is for me to read this blog post in two minutes and getting back to work.

I don’t think i have to say what mode these commands have to be used in.

  • i to insert text
  • Esc to exit edit mode
  • v for visual select
  • shift + v or V for visual lines
  • ctrl + vfor visual block
  • y to yank/copy
  • x to cut/delete
  • p to paste on the next line.
  • shift + p or P to paste right where the cursor is.
  • :w to write
  • :q to quit
  • :wq to save and quit
  • :e filename to open a new buffer with file specified
  • :ls to list all the buffers. # is the previous buffer. %a is the active buffer
  • :b buffernumber to switch to that buffer
  • :b # to switch to the previous buffer
  • :bd buffernumber to delete a particular buffer.
  • u to undo

This should be enought to get you going.

Git – Quick Start

This is meant to be a quick revision of very basic Git commands for me. I am not yet a fully functional software developer at the moment. I do not use a lot of Git. But then i do rarely, once a year maybe for some small project?, and, this can be good starter for me.

  • git init to initialize a repository in a folder.
  • git status to know the status of what is staged, what is modified and such.
  • git add filenames to stage those files.
  • git commit -m "Commit Message" to commit staged files with a commit message.
  • List files that need to be excluded when staging whole folders maybe, in .git/info/exclude. Can be used for temporary files and media files maybe.
  • git rm --cached filename to remove a file from being monitored by git.

That should get you started dear future me! 🙂