views:

350

answers:

3

I have text file:

    gvim file.txt


In UNIX you can type this at any command prompt.  If you are running Microsoft
Windows, open an MS-DOS prompt window and enter the command.
   In either case, Vim starts editing a file called file.txt.  Because this
is a new file, you get a blank window. This is what your screen will look
like:



    +---------------------------------------+
    |#                                      |
    |~                                      |
    |~                                      |
    |~                                      |
    |~                                      |
    |"file.txt" [New file]                  |
    +---------------------------------------+
          ('#" is the cursor position.)

The tilde (~) lines indicate lines not in the file.  In other words, when Vim
runs out of file to display, it displays tilde lines.  At the bottom of the
screen, a message line indicates the file is named file.txt and shows that you
are creating a new file.  The message information is temporary and other
information overwrites it.

Tree file:

^$
text. text\n   - join lines in this block, because ends block dot
more text.\n
^$
^$
text.\n
text: text\n    - join lines in this block, because ends block >
more text>\n
^$
text.\n   - but not this, because don't ends '., :, > or !'
text\n
^$


TASK:

  1. I want to select a block of text with more than one line ending with ., :, > or ! using only regex
  2. Replace end of line characters to spaces
  3. How do I do this with vim, bash, perl, or awk to solve this task.

I want understand the difference in the operation, to select the best tool for working with text.


Trying to create a regex in Vim:

  1. /^\s*\(.*\).

    this select all block text

  2. /[!\.:>]$

    this select ended ., :, > or !

  3. /^\s*\(.*\)[!\.:>]$

    this select only line ended ., :, > or !

  4. /^\s*\(.*\)[!\.:>]

    this select only line containing ., :, > or ! therein

but my abilities are limited

A: 

to select a single line with multiple line endings:

/^(.*)[!.:>]$/;

If I was to attempt to process the block using perl then I would process it one line at a time and match each one.

Xetius
A: 

As an aside, if you're main purpose is to fix the line ending differences between Unix and Windows, it's worth knowing that the simple Unix tool dos2unix will convert text files in either direction.

ire_and_curses
I have a lot of files edited in Vim. Limit the width of text to 80 characters in line. I want to maintain the formatting of the document at the same time add lines of text as part of the opinion that vim shortened to 80 characters.
RA
A: 

In vim, do this:

:#s/^(.*)[!.:>]$/ /gc;
Cody Frazer