LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2004, 03:34 PM   #1
3inone
Member
 
Registered: Jul 2003
Distribution: redhat 8.0, 9.0, FC3
Posts: 32

Rep: Reputation: 15
sed and its hold buffer????????


/\/$/d
s/[\*\=\@\|]$//
s/^\.\//\//
s/^\.:/\//
s/:$//
:loop
/^\/.*$/,/^$/ {
/^$/! {
$! {
/^\/.*$/ {
h
bloop
}
/^\/.*$/!s/^\/.*$/G&/ < ========== line in question
}
}
}


I know that this is not the right syntax; but this is the idea:
I want be able to grab the first line in a block of lines and pre append it to all the rest of the lines in the block. The file at the point of :loop has blocks of lines that start with “/” as the first character in the first line of the block and end the block with a blank line.

Sample data in text file

/this is the first line
the second
the third
the forth
< ===== blank line – end of block

to end up with after sed runs its script file

/this is the first line
/this is the first line the second
/this is the first line the third
/this is the first line the forth
< ===== blank line – end of block
PS the space inserted between “line” and “the” is intended.
 
Old 05-06-2004, 03:35 PM   #2
3inone
Member
 
Registered: Jul 2003
Distribution: redhat 8.0, 9.0, FC3
Posts: 32

Original Poster
Rep: Reputation: 15
sorry about the lost of format (damn windoze machine).
 
Old 05-07-2004, 05:56 AM   #3
arvind_sv
Member
 
Registered: Oct 2002
Location: Bangalore
Distribution: Gentoo Linux
Posts: 96

Rep: Reputation: 16
Hi,

How about something like this?

Code:
:s
h
p
n

:x
/^$/! {
    G
    s/\(.*\)\n\(.*\)/\2 \1/
    p
    n
    bx
}

p
n
bs
Arvind
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
modem on hold zefor Linux - Software 1 02-10-2004 07:16 PM
4.0 GIGS!!! Can they hold???? phenryr_13 Linux - Newbie 2 01-21-2004 10:35 PM
hold up for the newbie kylesoule Linux - General 2 09-04-2001 07:39 PM
getting a hold of slackware 8 makai Linux - Distributions 4 07-04-2001 03:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration