How can I join these lines

How can I join these lines

Post by Mr Chung Chi Wo » Sun, 19 May 1996 04:00:00



Hello Everybody,

        I have a file contains the following lines :

                begin .......................
                ...............................
                ..............................
                end ..........................

                other stuff

                begin......................
                ...........................
                ......................
                end................

                other stuff

        My question is how can I join all of the lines between "begin"
and "end"?

        Thanks.

Chi-Chung

 
 
 

How can I join these lines

Post by Randal L. Schwar » Sun, 19 May 1996 04:00:00


Chung> Hello Everybody,
Chung>       I have a file contains the following lines :

Chung>               begin .......................
Chung>               ...............................
Chung>               ..............................
Chung>               end ..........................

Chung>               other stuff

Chung>               begin......................
Chung>               ...........................
Chung>               ......................
Chung>               end................

Chung>               other stuff

Chung>       My question is how can I join all of the lines between "begin"
Chung> and "end"?

        perl -pe 's/\n/ / if /begin/../end/ =~ /^\d+$/' <infile >outfile
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Web: <A HREF="http://www.teleport.com/~merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me

 
 
 

How can I join these lines

Post by Heiner Stev » Mon, 20 May 1996 04:00:00



 >   I have a file contains the following lines :

 >           begin .......................
 >           ...............................
 >           ..............................
 >           end ..........................

 >           other stuff

 >           begin......................
 >           ...........................
 >           ......................
 >           end................

 >           other stuff

 >   My question is how can I join all of the lines between
 >   "begin"  and "end"?

    awk '/^begin/, /^end/' DATA

This command includes the "begin/end" delimiter.

Heiner
--

World - Europe - Germany - Bavaria - Nuernberg

 
 
 

1. sed: act on previous line, and join two lines?

There are two actions I frequently wish I could do with sed, but always end
up doing it some other way. Anyone know how to do these? I may use
combinations of tr, sed, cut, and paste right now to do all this, but I'd
rather just use sed.

1. select or print a single line immediately preceding an identified line.
For example, in a text file with FF page breaks, I want every line that
immediately precedes the FF line. Of course, I may also wish to target the
4th line before the FF line, or maybe the 2nd line after the FF line, etc.
(you get the idea). In an old line editor I used to use, I could use the
regexp "/^L/-1" to find the FF line, and then position backwards 1 line.

2. join two lines. For example, in a text file with FF page breaks, I want
to append the FF line to the line immediately preceding it (in vi I can use
the "J" command to join two lines).

--

Internal Systems Coordinator
DataMirror Corporation  (anti-spam email address suffix in use)

2. Registro SPF en servidor linux debian.

3. please help how to join 3 lines into one line via script

4. drag & drop

5. How to unconditionally join two files lines by lines?

6. X-based Flow Charting Tool.

7. How to join lines wiht the line number in sed ?

8. probleme boot linux red hat 7.1

9. Join lines where line DOES NOT end with a semicolon

10. Join multiple lines of records to single line

11. join lines but leave blank lines alone

12. join two lines in a file with a script

13. Join "\" lines in a file