Question

What is the special character which indicate first ?

if we do

$ vi .bashrc
$ source !$

this !$ will replaced by .bashrc because ! means previous line(am I correct?), $ means last word (for sure)

then what is first?

I want to insert some string in every line in vi editor using :%s/find-key-word/replaced-keyword/g

in here, if I put :%s/$/example/g in vi editor, it will append in all lines with example.

I want to insert all in front of all string every line.

I know I can use visual block (ctrl+v) and select all front lines and insert (shift+i) insert some word and escape(esc) will do the same... but I want to do in one shot..

please let me know how to do..

Thanks in advance

Was it helpful?

Solution

There are two questions, so you are getting two kinds of answers :)

The bash command history has only a passing similarity to the vi regular expression syntax.

^ is the beginning of line in vi. $ is the end of line in vi.

!!:0 is one way of accessing the first word of the previous command in bash

!$ is one way of accessing the last word of the previous command in bash

OTHER TIPS

To indicate beginning of line, the symbol used is:

^

See an example:

$ cat a
hello!
this is me
testing some
stuff
$ sed 's/^/XXX/' a
XXXhello!
XXXthis is me
XXXtesting some
XXXstuff

The character you are looking for is ^.

For example, :%s/^/example/g will prepend all lines with the string example.

In bash, !^ refers to the first argument of the previous command, and !$ the last argument.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top