You are not logged in.

#1 2005-05-20 01:08:46

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

cutting lines sequentially using bash[solved]

from a kernel PKGBUILD, I need to be able to cut the following line and all other lines below it so I can echo it into a file. :   
cat ../config | sed "s|#CARCH#|$carch|g" >./.config

Offline

#2 2005-05-20 01:18:55

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: cutting lines sequentially using bash[solved]

Not sure what the question is, nor what exactly you want to do, so I'll take a wild guess:

cat << END > somefile
cat ../config | sed "s|#CARCH#|$carch|g" >./.config
...
...
END

Offline

#3 2005-05-20 01:53:05

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: cutting lines sequentially using bash[solved]

sorry

cat ../config | sed "s|#CARCH#|$carch|g" >./.config

is the complete line off the file. I needed that line and all lines below it echoed into another file such as temp.bottom and if possible, remove the bottom half of the original file in which it came. Basically like a "cut and paste" if you were using a gui. Essentially, I want to insert my own lines after that given line and put the rest back in place.

Offline

#4 2005-05-20 01:59:17

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: cutting lines sequentially using bash[solved]

Best to just make a diff and use patch to do it. There are other ways, but that's probably the cleanest solution. Though that line is strange as it is, why don't you do it yourself instead of letting .config do the cat/sed commands?

Offline

#5 2005-05-20 02:15:38

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: cutting lines sequentially using bash[solved]

Its for a program I'm doing. It can use any of the kernel PKGBUILDS so, the only line that is common, and Im concerned with is "cat ../config sed | bla blawant" I just want to be able to insert my command before it. If each of these PKGBUILDs are different. Will I still be able to patch as you suggested. If so could you give me an example of how to do it?

Offline

#6 2005-05-20 03:14:37

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: cutting lines sequentially using bash[solved]

You could do something like the following, though there must be a better way:

sed 'sXcat ../config | sedXblablancat ../config | sedX'

Offline

#7 2005-05-20 04:51:02

rasat
Forum Fellow
From: Finland, working in Romania
Registered: 2002-12-27
Posts: 2,294
Website

Re: cutting lines sequentially using bash[solved]

What I understand, the idea is to goto a particular line in PKGBUILD and insert new lines with stuff.

I did a search (sed find and insert) and found this link:
http://www.unix.com/archive/index.php/t-9831.html

EDIT
Here is a sample to insert text under the "build() {" line with append "a" (to insert above the line use "i")

sed '/^build() /a
your text goes here' /test/PKGBUILD > /test/PKGBUILD.test

Link:
http://anaturb.net/sed.htm


Markku

Offline

#8 2005-05-20 12:32:53

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: cutting lines sequentially using bash[solved]

that works good for build() but it doesn't like the line I need. Seems like the forward slash in it ends it prematurely.  I guess I'll have to read up on sed more later...damn tricky a$$ sed. :x

Offline

#9 2005-05-20 13:31:16

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: cutting lines sequentially using bash[solved]

you dont have to use / for sed you know, you can use other characters like @ too. take a look in the manual, there should be some listed.

Offline

#10 2005-05-27 00:09:37

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: cutting lines sequentially using bash[solved]

I got it working by using:

sed '/cat ../config | sed "s|#CARCH#|$carch|g" >./.config/i
bla
bla' sourcefile > tempfile

thanks for everyone's help

Offline

Board footer

Powered by FluxBB