If you specifically mean the first line of the body from the response, now you need to define "first line" a little, and you should really get an HTML-aware parser. I could probably do it in sed , but it's really kind of a bad idea in most cases. If that's really what you need, let me know, supply some additional details, and we'll work on it.
edit
OP requested the lines be in the reverse order, so I offered this:
To explain the sed - sed -n says n o output unless I ask for it. 1h; says on line 1, h old the data in the pattern buffer (the line just read, since we haven't edited it) in the "hold" buffer. ${ says on the last line, open a set of commands to execute, which will be closed with the matching } close brace. p;x;p; -
p means p rint the current pattern buffer, which on the last line will be the last line just read in.
x means e x change the hold and pattern buffers. This puts line 1, still in the h old buffer, into the standard pattern buffer space.
p again p rints the new value of the pattern buffer, which is the held line 1.
2条答案
按热度按时间olhwl3o21#
Don't send it to /dev/null?
-o
is throwing it away.If you ONLY want the first line, as your title suggests, filter it.
This tells sed to print the first and last lines, because you asked for the first one, and
-w
prints after completetion. My test:If you specifically mean the first line of the body from the response, now you need to define "first line" a little, and you should really get an HTML-aware parser. I could probably do it in
sed
, but it's really kind of a bad idea in most cases.If that's really what you need, let me know, supply some additional details, and we'll work on it.
edit
OP requested the lines be in the reverse order, so I offered this:
To explain the
sed
-sed -n
saysn
o output unless I ask for it.1h;
says on line 1,h
old the data in the pattern buffer (the line just read, since we haven't edited it) in the "hold" buffer.${
says on the last line, open a set of commands to execute, which will be closed with the matching}
close brace.p;x;p;
-p
meansp
rint the current pattern buffer, which on the last line will be the last line just read in.x
means ex
change the hold and pattern buffers. This puts line 1, still in theh
old buffer, into the standard pattern buffer space.p
againp
rints the new value of the pattern buffer, which is the held line 1.dly7yett2#
您可以使用以下
curl + awk
解决方案: