Discussion:
Trouble with sed and semicolon delimiter...
(too old to reply)
Tom Lynch
2022-01-19 13:51:02 UTC
Permalink
Greetings,

I'm having trouble with the sed portion of a bash script. I'm trying to get
all the tags from BitBake recipes. I have the following line:

SRC_URI = "git://bb/foo.git;protocol=ssh;tag=v1.1.0;lfs=0;subpath=pctrlmc/c2cmtd"

What I would like to get is the "v1.1.0" of the "tag=" portion

I'm using the following to parse, since this is a BitBake recipe, I need to account for line extensions, so I run it through a perl script first, but the entire line:

perl -pe 's/\\\n|\s{2,}/ /g' foo.bb | grep SRC_URI | grep -v '#' | sed -r 's#.*tag=(.?+)(;|\s+|\").*#\1#'

What this gets is:

v1.1.0;lfs=0;subpath=pctrlmc/c2cmtd

it's missing the semicolon delimter, if I change the sed to:

sed -r 's#.*tag=(.?+);.*#\1#'

It's still missing the first semicolon

v1.1.0;lfs=0

I need to account for other types of delimiter, thus the (;|\s+|\"), but no matter what I've tried, I can't seem to capture just the tag there. What I'm I doing wrong?

Thanks in Advance for any help!

Tom
Michael F. Stemper
2022-01-19 14:28:57 UTC
Permalink
Post by Tom Lynch
Greetings,
I'm having trouble with the sed portion of a bash script. I'm trying to get
SRC_URI = "git://bb/foo.git;protocol=ssh;tag=v1.1.0;lfs=0;subpath=pctrlmc/c2cmtd"
Are you sure that's what you have? When I execute that line, I get

$ SRC_URI =
"git://bb/foo.git;protocol=ssh;tag=v1.1.0;lfs=0;subpath=pctrlmc/c2cmtd"
SRC_URI: command not found
$

(Give or take the gratuitous line-wrap inserted by Thunderbird)
Post by Tom Lynch
What I would like to get is the "v1.1.0" of the "tag=" portion
I know nothing about perl, so I can't help with that.

Can you just use sed?

$
SRC_URI="git://bb/foo.git;protocol=ssh;tag=v1.1.0;lfs=0;subpath=pctrlmc/c2cmtd"
$ echo $SRC_URI | sed 's/.*;tag=//' | sed 's/;.*//'
v1.1.0
$
--
Michael F. Stemper
Nostalgia just ain't what it used to be.
Tom Lynch
2022-01-19 16:26:00 UTC
Permalink
Post by Michael F. Stemper
Post by Tom Lynch
SRC_URI = "git://bb/foo.git;protocol=ssh;tag=v1.1.0;lfs=0;subpath=pctrlmc/c2cmtd"
Are you sure that's what you have? When I execute that line, I get
$ SRC_URI =
"git://bb/foo.git;protocol=ssh;tag=v1.1.0;lfs=0;subpath=pctrlmc/c2cmtd"
SRC_URI: command not found
Yes, I should be more specific, this is the BitBake line I'm trying to parse to get the version from,
it's just an example.
Post by Michael F. Stemper
Can you just use sed?
$
SRC_URI="git://bb/foo.git;protocol=ssh;tag=v1.1.0;lfs=0;subpath=pctrlmc/c2cmtd"
$ echo $SRC_URI | sed 's/.*;tag=//' | sed 's/;.*//'
v1.1.0
That is a possibility, hadn't thought of breaking it into two sed commands...

Thanks
Post by Michael F. Stemper
$
--
Michael F. Stemper
Nostalgia just ain't what it used to be.
Loading...