Good: Vi Editor- Writing Your Own Cheat Sheet In 10 Days

History:

[img] https://scontent-b-sjc.xx.fbcdn.net/...56054850_o.jpg [\img]

The name vi is derived from the shortest unambiguous abbreviation for the command*visual*in ex;

But vi was created in 1976, by the co-founder of SUN ie Bill Joy .
They had only one editor called ed. They had to use uppercase for it.

What happened is that Ken Thompson came to Berkeley and brought this broken Pascal system, and the team of 3 got this summer job to fix it. While we were fixing it, they got frustrated with the editor they were using which was named ed.

So they had a terminal at home and a 300 baud modem so the cursor could move around and they just stayed up all night for a few months and wrote vi.


How to invoke
Go to the terminal and type vi or gvim.
Vi is the older version, Your mouse will not work over this screen.
So use gvim, This is a newer version of gvim and is easy to use.

Basic Editing
The Vim editor is on of the most powerful text editors around. It is also extremely efficient, enabling the user to edit files with a minimum of keystrokes.

You may face problems in getting adjusted to vi. But hang on, every minute is worth it.


Vim starts editing a file

go to the editor and type vi <file name> or gvim <file_name> and hit enter. you will get a new window to start entering data. Initially you will be in the normal mode, to enter the data you have to enter to the insert mode where the vi start accepting data. so press 'I' and enter the required data.

Modes

The Vim editor is a modal editor. That means that the editor behaves
differently, depending on which mode you are in. If the bottom of the screen
displays the filename or is blank, you are in normal mode. If you are in insert
mode, the indicator displays --INSERT--; and if you are in visual mode, the
indicator shows --VISUAL--.

Editing for the First Time

The next few sections show you how to edit your first file. During this process, you learn the basic commands that you have to know to use Vim. At the end you will know how to edit--not fast, not efficiently, but enough
to get the job done.


Inserting Text
To enter text, you need to be in insert mode. Type i, and notice that the
lower left of the screen changes to --INSERT-- (meaning that you are in insert
mode).
Now type some text. It will be inserted into the file. Do not worry if you make mistakes; you can correct them later.


After you have finished inserting, press the <Esc> key. The --INSERT--
indicator goes away and you return to normal mode. (The indicator for this
mode is a blank indicator.) Your screen should now look something like Figure


Save the file
To save your changes type :w,
If you have opened in a read only mode, you have to force write it, so inset :w! .
This will force write the file

Getting Out of Trouble
One of the problems for Vim novices is mode confusion, which is caused by
forgetting which mode you are in or by accidentally typing a command that
switches modes. To get back to normal mode, no matter what mode you are in,
press the <Esc> key.


Moving Around

After you return to normal mode, you can move around by using these
keys: h (left), j (down), k (up), and l (right). At first, it may appear that these
commands were chosen at random. After all, who ever heard of using l for
right? But actually, there is a very good reason for these choices: Moving the
cursor is the most common thing you do in an editor, and these keys are on the
home row of your right hand. In other words, these commands are placed where
you can type them the fastest.

You can move the cursor by the arrows also, But if your have them missing you can use the above said options.

Deleting Characters

To delete a character, move the cursor over it and type x. (This is a
throwback to the old days of the typewriter, when you deleted things by typing
xxxx over them.) Move the cursor to the beginning of the first line, for example,
and type xxxxxxx (seven x's) to delete the first seven characters on the line.


Undo and Redo

u

Type a text, and delete first 5 letters of the text. And lets see how to undo the changes ( one character at a time)

Type u to undo the last delete. That delete removed the g, so the undo
restores the character.

ctrl+R
Reverse the changes
This will un do the previous command. Use this if you want to use 'u ' a lot of times.


U

There's a special version of the undo command, the U (undo line) command.The undo line command undoes all the changes made on the last line that was
edited.

This will restore all the changes done on the command.

Save

To exit, use the 'w' or 'w!' command. This command writes the file (if modified)
and exits.

discard

It is :q!. For those of you interested in the details, the three parts of this command are the colon (, which enters command mode; the q command, which tells the editor to quit; and the override command modifier (!).

q-quit

***************
Deleting a line

To delete a line, use the dd command, which deletes the line on which the
cursor is positioned.

Or use S. But this will enter into the insert mode right after deleting the line

to mention data between lines, Use the : and mention the line numbers and type d and enter.

Opening Up New Lines

To add a new line, use the o (lower case)command to open up a new line
below the cursor. The editor is then placed in insert mode.

To open a line above the cursor use the upper case 'O'.

Moving to the Start or End of a Line

END
The $ command moves the cursor to the end of a line. Actually, a bunch of
keys map to the "end-of-line" command.


The $ command takes a numeric argument as well. If present, it causes
the editor to move to the end of the next line. For example, 1$ moves you to the
end of the first line (the one you're on), 2$ to the end of the next line, and so on.


START
The ^ command moves to the first nonblank character of the line. The
<Home> or <kHome> key moves to the first character of the line, (The 0 [zero] command does the same thing.) Like every other command
previously discussed, these commands (except 0 [zero]) can take a numeric
argument. They do not do anything with it, but you can specify it if you want to.


Word Movement

Let's start with movement. To move the cursor forward one word, use the w
command. The b command moves backward one word. Like most Vim
commands, you can use a numeric prefix to move past multiple words. For
example, 4b moves back four words.


Moving to a Specific Line

can use the :set command in many different ways, which are described in
Chapter 28: Customizing the Editor. The 'number' option is a boolean option,
meaning that it can be on or off. To turn it on, use this command:
:set number
To turn it off, use this command:
:set nonumber


Where Am I?
The CTRL-G command displays a status line that indicates where you are in
the file. For example:
This indicates that you are editing a file called c2.txt, and that it has been
modified since the editing started. The cursor is positioned on line 81 out of a
total of 153, or about 52% of the way through the file. The cursor is currently
sitting in column 1.

Scrolling Up and Down

The CTRL-U command scrolls up half a screen of text. (Up in this case is
backward in the file; the text moves down on the screen. Don't worry if you have
a little trouble remembering which end is up. Most programmers have the same
problem.) The CTRL-D command scrolls you down half a screen.

Deleting Text

uppose you want to delete part of a line, say a word. The way to do that is
to start visual mode with the v command. You can now highlight the text you
want to delete with the cursor movement commands.

Deleting Text Without Visual Mode
It is possible to delete sections of text without using the visual mode. The
advantage of doing things non-visually is that you save a single keystroke. The
disadvantage is that you really have to know what you are doing as there is no
visual feedback to show you what's going on.


Visual vs. Normal Mode Delete
The visual method of deleting things lets you see exactly what you are
going to delete before you delete it. You can also make adjustments before you
delete the text. This makes things much easier for large complex deletes.
On the other hand, the normal mode delete provides no feedback. You
type d and a motion command and hope you did the right thing. (If you didn't
there's always the undo command.) The advantage of the normal mode method
of doing things is that it's quicker for small amounts of text, especially when you
know where the motion command is going to send the cursor. In other words if
you have to delete three words, d3w is probably what you want to use. But if
you have to delete 57 words (maybe 57 you're not sure) the v<move>d is better.


Changing Text

The c command changes text. It acts just like the d command, except it
leaves you in insert mode. For example, if you go into visual mode (v) highlight a
word (w) and then press c, the word will disappear and you'll be left in insert
mode.


Joining Lines

To join a set of lines in visual mode, start visual mode (v) highlight the lines
you wish to join, and press J. All the highlighted lines will be put together in
one big line. A space is placed between the pieces that are joined

Replacing Characters

The r{char} command replaces the character under the cursor with
{char}. Figure 2-18 shows how you can use the r command to replace a z with
an s. The r command can be preceded with a count, indicating the number of
characters to be replaced. In Figure 2-19, we go to the beginning of line (the ^
command) and execute 5ra to replace the first five characters with a.

Changing Case

The ~ command changes a character's case. It changes uppercase to
lowercase and vice versa. If a count is specified, the count characters are
changed.

*********

Simple Searches

To search for a string, use the /string command. To find the word
include, for example, use the command /include. An <Enter> is implied at the
end of this command. (Any time the cursor jumps to the bottom of the screen
and you type something, you must end it with <Enter>.)

Search History

Use the up arrow to move to the previous command used.
Else type the "History" to print the recent command history

also use the command "q/" to open the history window.

Searching Options Highlighting

The following command causes Vim to highlight any strings found
matching the search pattern:
:set hlsearch
If you turn on this option and then search for include, for example, all the
include strings are highlighted, as seen in Figure 3-4. To turn off search
highlighting, use this command:
:set nohlsearch
To clear the current highlighting, use the following command:
:nohlsearch
Search highlighting is now turned off; matched text will not be highlighted.
However, the highlighting will return when you use a search command.

Incremental Searches

By default, Vim uses the traditional search method: You specify the string,
and then Vim performs the search. When you use the following command, the
editor performs incremental searches:

:set incsearch

Next, you start the search by typing the /i command. Figure 3-5
shows how the editor searches for the first i and positions the cursor on it.

To turn off incremental searches, use the following command:
:set noincsearch



Searching Backward

The reverse search command (?) searches backward. The n command
repeats the last search. If a reverse search was the last one used, the n
command searches in the reverse direction. If the last search was a forward
search, the n command searches forward.


Reverse Search History
Like forward search (?) you can use the <Up> and <Down> keys to go
through the search history. You can also open a search history for reverse
searches with the command q?.


Changing Direction
Suppose you start a forward search for unsigned using the /unsigned
command. You can turn around and search in the reverse direction by using the
? Command. The n command repeats the search in the same direction. The N
command reverses the direction on the search and repeats it. To make things a
little clearer, line numbering has been turned on using the following command:

Basic Regular Expressions

The Vim editor uses regular expressions to specify what to search for.
Regular expressions are an extremely powerful and compact way to specify a
search pattern. Unfortunately, this power comes at a price because regular
expressions are a bit tricky to specify. Let's start with the simple stuff. In a
regular expression, the normal letters match themselves.


The Beginning (^) and End ($) of a Line

The ^ character matches the beginning of a line. (It is no coincidence that
this is also the command to move to the beginning of the line.) The expression
include matches the word include anywhere on the line. But the expression
^include matches the word include only if it is at the beginning of a line.
The $ character matches the end of a line. Therefore, was$ finds the word
was only if it is at the end of a line. Figure 3-10, for example, shows a search for
the pattern the with highlighting enabled.


Match Any Single Character (.)

The character . matches any single character. For example, the
expression c.m matches a string whose first character is a c, whose second
character is anything, and whose third character is m. Figure 3-13 shows that
the pattern matched the com of computer and the cam of became.


Matching Special Characters

Most symbols have a special meaning inside a regular expression. To
match these special symbols, you need to precede them with a backslash (\). To
find the] , for example, use the string the\].

Regular Expression Summary

Character Meaning
x The literal character x
^ Start of line
$ End of line
, A single character
\x Turns off the special meaning of many characters, gives special

**********
Cut, Paste, and Copy

When you delete something with the d, x, or another command, the text is
saved. You can paste it back by using the p command. (The Vim name for this is
a put, but everyone else calls it “paste”).

If you delete part of a line (a word with the dw command,
for instance), the p command puts it just after the character under the cursor


Character Twiddling

Frequently when you are typing, your fingers get ahead of your brain. The
result is a typo such as teh for the. The Vim editor makes it easy to correct such
problems. Just put the cursor on the e of teh and execute the command xp.

x Deletes the character e and places it in a register.
p Puts the text after the cursor, which is on the h.

Moving Large Blocks of Text

Let's say you wish to move 57 line block of text from one place to another.
One solution is to perform the following commands:
1. Put the cursor on the first line of the block
2. Type 57dd to delete the block.
3. Move the line just before where you want to insert the block.
4. Execute p to “put” the block on the line after the one the cursor is on.


moving selected lines to a file

To move few lines of a large file to another file , mention the start line and end line and give the new name in the command mode
: 1, 445 w! file_name

This will save the content in the new file "file_name"



To delete selected lines

Mention the deleted lines and press dd

eg :1, 25 dd

This command will delete the lines. These commands becomes very handy when you want to manipulate the data.


So to move a block using line visual mode, we execute the following commands:

1. Put the cursor on the first line of the block.
2. Start line visual mode with the V command.
3. Put the cursor on the last line of the block.
4. Delete the text with the d command (visual delete).
5. Move the line just before where you want to insert the block.
6. Execute p to “put” the block on the line after the one the cursor is on.

Marks

The Vim editor enables you to place marks in your text. The command ma
marks the place under the cursor as mark a. You can place 26 marks (a through
z) in your text. (You can use a number of other special marks as well.)
To go to a mark, use the command `{mark}, where {mark} is the mark
letter (and ` is the backtick or open single-quote character).
The command '{mark} (single quotation mark, or apostrophe) moves you
to the beginning of the line containing the mark. This differs from the `{mark}
command, which moves you to the marked line and column.


1. Move the cursor to the beginning of the text you want to delete.
2. Mark it using the command ma. (This marks it with mark a.)
3. Go to the end of the text to be removed. Delete to mark a using the
command d'a. (Entire lines will be deleted since 'a is a line type move.)

Note:There is nothing special about using the a mark. Any mark from a to
z may be used.


One nice thing about marks is that they stay with the text even if the text
moves (because you inserted or deleted text above the mark. Of course, if you
delete the text containing the mark, the mark disappears.

Yanking

For years, I used a simple method for copying a block of text from one
place to another. I deleted it using the d command, restored the deleted text
with the p command, and then went to where I wanted the copy and used the p
to put it into the text.
There is a better way. The y command "yanks" text into a register (without
removing it from the file). (Every other editor calls this a “copy”.)



The general form of the normal mode y command is y{motion}. It works
just like the delete (d) command except the text is not deleted. And the
shorthand yy yanks the current line into the buffer.

Paste it with "p"


Filtering

The linux commands will work in vi.

! Is a command utility that is very help full.
when you select the data and press !, This will pass the selected data to the particular command. Let us see this in the particular example

You want to sort lines 1 through 10 of a file.
First start visual mode (v) and highlight the first 10 lines. Then press !.
In anticipation of the filtering, the cursor drops to the bottom of the screen
and a ! prompt displays. You can now type in the name of the filter program, in
this case sort. Therefore, your full command is as follows:

!sort<Enter>


The !! command runs the current line through a filter. (I have found this a
good way to get the output of system commands into a file.)


I'm editing a
readme.txt file, for example, and want to include in it a list of the files in the
current directory. I position the cursor on a blank line and type the following:

This puts the output of the ls command into my file. (Microsoft Windows
users would use dir.) Another trick is to time stamp a change. To get the
current date time (on UNIX), I use the following command:
!!date
This proves extremely useful for change histories and such.
Note: Using !! like this is technically not filtering because commands like
ls and date don't read standard input.

Editing Another File

Suppose that you have finished editing one file and want to edit another
file. The simple way to switch to the other file is to exit Vim and start it up again
on the other file. Another way to do so is to execute the following command:
:e file
Note: :e is an abbreviation for :edit.
This command automatically closes the current file and opens the new one.
If the current file has unsaved changes, however, Vim displays a warning
message and aborts the command

Or you can force Vim to discard your changes and edit the new file using
the force (!) option, as follows:
:e! file
To edit a new,unnamed buffer use the :enew (:ene) command. It works
just like :edit only the new buffer is unnamed.

The Write command
To save the changes
At this point, you have a number of options. You can write the file using
this command:
:write
Note: :w may be used instead of :write.


The :view Command

The following command works just like the :vi command, except the new
file is opened in read-only mode:
:view file
Note: :vie may be used instead of :view.


Dealing with Multiple Files


So far the examples in this book have dealt with commands that edit a
single file. This section introduces you to some commands that can edit multiple
files. Consider the initial Vim command, for example. You can specify multiple
files on the command line, as follows:
$ gvim one.c two.c three.c
This command starts Vim and tells it that you will be editing three files.


To edit the next file, you need to change files using the :next command
(:n)


Note that if you have unsaved changes in the current file and you try to do
a :next, you will get a warning message and the :next will not work. You can
solve this problem in many different ways. The first is to save the file using the
following command:
:write
In other words, you can perform a :write followed by a :next. The Vim
editor has a shorthand command for this. The following command performs both
operations:
:wnext

Or, you can force Vim to go the next file using the force (!) option. If you
use the following command and your current file has changes, you will lose those
changes:
:next!


Auto Write Option
Finally, there is the 'autowrite' ('aw') option. If this option is set, Vim
will not issue any No write... Instead, it just writes the file for you and goes
on. To turn this option on, use the following command:
:set autowrite
To turn it off, use this command:
:set noautowrite
You can continue to go through the file list using the following command until
you reach the last file:
:next

:2 next


Which File Am I On?
Suppose you are editing a number of files and want to see which one you
are on. The following command displays the list of the files currently being
edited:
:args
The one that you are working on now is enclosed in square brackets.

Going Back a File
To go back a file, you can execute any of the following commands (all are
equivalent):
revious
rev
:Next
:N
These commands act just like the :next command, except that they go
backward rather than forward. If you want to write the current file and go to the
previous one, use any of the following commands:
:wprevious
:wp
:wNext
:wN

Matching

Though not exactly a search command, the :match (:maxx) command can
be very useful in finding test. It causes all text that matches a given pattern to
be highlighted on the screen. For example, to highlight all the word “TODO”
with the Error syntax highlighting, use the command:
:match Error /TOOD/


To find out what highlighting names are available use the :highlight (:hi)
command:
:highlight

To remove the mathched the patterns use
:match none

There are can be three matches active at one time. These are set by the
:match, :2match, and :3match commands. If some text is matched by more than
one command, the lowest one wins.

*******
Opening a New Window

The easiest way to open a new window is to use the following command:
:split

This will split the window horizontally

The :split (:sp) commands divides the screen horizontally. To divide the
screen vertically use the :vsplit (:vs) command. Figure 5-3 shows the result of
this operation:


Than you can open the required file.
Suppose you want to split and open a file directly than you have to use the below command

The following command opens a second window and starts editing the
given file:
:split file

Controlling Window Size


The :split (:sp) command can take a number argument. If specified,
this will be the number of lines in the new window. For example, the following
opens a new window three lines high and starts editing the file alpha.c:

:3 split alpha.c
A space appears here for clarity. You could have just as easily write the
following:
:3split alpha.c

To Open a New Window

The :new Command

The :new command works just like the :split command except that the
:split command splits the current window and displays the current file in both
windows while :new opens a window containing a new, empty file.


Split and View
The :sview (:sv) command acts like a combination of :split and :view.
This command proves useful if you want to look at, but not edit, a file in another
window.
There is no :vsview command. However if you wish to split the window
vertically and edit a file you can use the :vertical :sview (:vert :sview)
command. The :vertical command tells Vim to perform the command that
follows splitting the window vertically instead of horizontally.

Change the size of the Windows.
The command count CTRL-W+ increases the window size by count (default
= 1). Similarly count CTRL-W- decreases the window's size by count (default =
1). The command CTRL-W= makes all the windows the same size (or as close as
possible).
The command count CTRL-W_ (CTRL-W CTRL-_) makes the current window
count lines high. If no count is specified, the window is increased to its maximum
size.
The :resize (:res) command can be used to change the height of the
window from the command line. The argument to this command can be an
simple number (i.e. 24) in which case the window is set to that size. If the
argument begins with a plus or minus, (i.e. +5, -7), then the window in increased
or decreased in size.
If no argument is given to the :resize command, the window is enlarged
to it's maximum height.

Buffers

The Vim editor uses the term buffer to describe a file being edited.
Actually, a buffer is a copy of the file that you edit. When you finish changing the
buffer and exit, the contents of the buffer are written to the file. Buffers not only
contain file contents, but also all the marks, settings, and other stuff that go with
it.

Normally it is pretty easy to tell what buffers you have: If it has a window
on the screen, it is a buffer; if it is not on the screen, it is not a buffer.

This is a way to edit multiple files at a time with out closing it, discarding any changes
U can keep them hidden , retrive and edit them as u want.

Any buffer can be in
Active Appears onscreen.
Hidden A file is being edited, but does not appear onscreen.
Inactive The file is not being edited, but keep the information about it
anyway.

To List the buffers

:ls
:buffers
:files

To hide a particular file/buffer
:hide
This will keep it in the back ground

:to open a particular buffer
hit :buffers/ls

To open the particular buffer
:buffer <file number or buffer number>

You can also split the buffers
:sbuffer <file>

To split vertically you can try
:vertical sbuffer <file name>


Buffer movement commands

:bnext
:bprevious
:blast
:sbnext

Tabbs in gvim

The Concept of tabs is also available in Gvim.

To edit a file in a tab, use the below command
:tabedit <file_name>

To create a new tab
:tab <file_name>

To cloase a tab we can use
:q
or
:tabclose


If your using a basi vi, where your mouse wont work, Use need to use the following commands to naviagiate between the tabs

:tablast
:tabfirst
:tabnext
:tabnext number
:tabprevious


Enjoy have a nice time learning..


Similar Content



What Do I Do With This Huge Data On My Command Line Interface

Hi,

I have been trying to get information on how to process the output of a tcl file (aodv and leach protocol using mannasim) which I got on my command line Iinterface. Actually, I don't even know the keywords to search as I am new to this and other minor attempts haven't yielded positive results., I know there is usually a trace file but I can't see any. All I see is on my command line.

I also observe that it took the space on the entire screen and I can't copy the output from the start ( I could only copy from node 19 out of 30 nodes) because of the huge number of output lines.

The last thing I havent been able to figure ou is whether temperature is equivalent to energy Iin mannasim as mannasim has only temperature and carbon dioxide?


Thanks

How To Search All Sub-directories For A File Or Command Line In A File In Ubuntu?

Hello--

I'm trying to locate a file or a command line in a file on my hard drive. I am running Ubuntu 12.05.4 linux. Is there a grep command that will search the whole tree from root down to all the sub-directories?

Thank You.

Search For A Character In Specific Word In File And Replace It In The Word

Hi all ,
I have a requirement where I have a file. Contents of the file are :
#comments
VAR="abg"
RES=123
#comments
IC6790ABG="https://www.abc.com"
IC5678-vg="https://www.bhy.com"
IC-gy_567:78="https://www.gyt.com"
#comments
The variable names can not have characters like - , : so
in this file I have to find words starting with IC and replace characters like - ,:
I want to change only the variable name , not the whole line.
I have used SED command

sed -i '/^IC/s/[^0-9 a-z A-Z _]*//g' file

when I am using this command , it is replacing the whole line
output becomes :

#comments
VAR="abg"
RES=123
#comments
IC6790ABGhttpswwwabccom
IC5678vghttpswwwbhycom
ICgy56778httpswwwgytcom
#comments


But I want the output like this :

#comments
VAR="abg"
RES=123
#comments
IC6790ABG="https://www.abc.com"
IC5678vg="https://www.bhy.com"
ICgy_56778="https://www.gyt.com"
#comments

How can I get the desired output , thanks for your help in advance .

Checking Presence Of A File Identified/ Addressed By A Variable

hi,

I am newbie in Linux shell scripting.Can anybody help me to check the presence of file identified by variable in Shell scripting?

For example: I am reading the content of a file using while command as below:
"while read -r line
do
code block
done < file_name"

Now in this case every line in file gets stored in the variable 'line' one by one.Problem here is every line in the file is nothing but the file_path of another file say xyz.txt and I am checking presence of this xyz.txt file using below command:
if [-f $line]
as 'line' is the variable which stores file path of xyz.txt but it is not working. It is unable to check the presence of this xyz.txt file as i am addressing it with the variable 'line'.

Please help me.Thanks in advance.

Write To Pipe File Hangs (using Echo Command)

HI,

I am a newbie to Linux and am trying to create a pipe file with the below command:

mkfifo pone

Now I am trying to write data to the file with the following command on the command prompt:

echo asdadsasdasdasdasdasd >./pone

But after i enter this command- the screen hangs up and doesnt proceed ahead.
Same thing happened when I tried writing using:
gedit pone


Can anyone help me resolve this issue?

Exporting Log Data To A File That Matches Stdout

hey guys,

Let's say I want to find out which log files have related ntp information in them. I use cat and grep to search through the files in /var/log and then export that to a file. this is the command...

# cat /var/log/* | grep ntp > /home/log.txt

The file created from this command will not include the directories the log entries are apart of. Why not? For example, if you do this same command without exporting to the /home/log.txt file it will show you in stdout which directory each log entry is in. Hope I'm making sense here. My question is, is there a clever way to export to a file in a way so that the file created is structured exactly like the stdout of the command below?

# cat /var/log/* | grep ntp

Removing Multiple Lines From Cell Data In A .csv File

I am trying to process some .csv files with Linux as follows:

Some fields have data with newline characters embedded, like so:

"Bob Smith
531 Pennsylvania Avenue
Washington, DC"

(I verified the existence of the " via Wordpad. The file is too large to easily edit in Wordpad to get all the data for each row on a single line).

what linux command would I use on the files to get the data in each cell on one line?

I have tried:

1. awk -v RS="" '{gsub (/\n/,"")}1' file > newfile

but the cell data was still being read in as if "531 Pennsylvania Avenue" was a brand new row in the CSV file.

2. Command 1 followed by awk -v RS="" '{gsub (/\r/,"")}1' newfile > finalFile

but that resulted in all of the data in the file being put onto a single line.

3. awk -v RS="" '{gsub (/\r\n/,"")}1' file > newFile

But that result was the same as attempt number 2.

How can I preprocess the file so that:

"Bob Smith
531 Pennsylvania Avenue
Washington, DC"

is read as a single field on a single line as part of the row it should be associated with, like

"Bob Smith 531 Pennsylvania Avenue Washington, DC"

How Do I Pass The Command Line Errors To A File.

I am writing a pythong program which has command line executions for linux like ls and restart. I want to know how to pass the errors from the command executed to a file so that it becomes a log.

How To Run A Command In Another Command?

I am not sure how to ask this, sorry.

if I had a code like this

Code:
# grep -a ": " md5list.txt | cut -f2,3 -d


How can I run the command basename for each line of the output?

basename {(grep -a ": " md5list.txt | cut -f2,3 -d )}


EDIT: A little more clarity on what im doing:
I didn't realize that 'md5sums' was a link to a nice formatted page. So I copied all packages here and put them into a text file. I decided to write a script that put all of these in that format.

So basically, even though I have already ran the md5sum -c 'md5sum-list' I still want to finish this small project because I am learning a ton.

Searching For Strings

If there is one Windows XP feature that I greatly miss in Mint, it is the Search Companion.

I have been struggling with 'grep' in order to create something suitable but with limited success. Take the following problem:-

I wish to interrogate the folder home/dell/Documents/Domestic/Recipes, searching for all files containing the word "mushroom" or "mushrooms", ignoring case. (I can manage the latter. )

Each individual file search should terminate at the first instance of a match and move to the next file. (Recursive, yeh?) Only the file names need to be listed and the output should be paged to allow for easier reading of long lists.

Several different types of file may be involved, including .doc, .odt, .txt .pdf, .htm and .rtf. It would be nice to include all of them in one command. (Wild card behaviour in grep is not entirely predictable - at least not for me.) Running a separate grep command for each different file type would be tedious.

A significant difficulty is that, if grep fails with a syntax, or run-time error, it generally reports the fact but it also has a habit of producing no output, perhaps not returning to the command prompt, whilst sitting inviting the user to decide what to do next. What makes this particularly frustrating is that some file types might not be amenable to a grep search. Text in .txt files and, it would appear, .doc files appears to be searchable but I suspect that .odt files might be more problematic. The snag in such circumstances is trying to interpret grep's response. Does a null return mean that no match was found or that the file format cannot be successfully interrogated? Such failure might not be apparent if the associated file names are simply excluded from the output list.

Apart from grep, is there any other software that would do the job? Sadly LibreOffice Writer seems to be lacking in this area.