Reputation
707
Top tag
Next privilege 1,000 Rep.
See votes, expandable usercard
Badges
5 23
Impact
~30k people reached

Jun
18
comment Print everything between two patterns, then delete first and last line of the resulting output
YES! This works. Thank you very much. I do have GNU sed here and the 1 must be replaced by 0. So what you're saying is, for the 1 case, pattern #1 must be preceded by some other data, or sed will fail. Of course, these things may happen :) Gladly the 0 variant will also work in both cases, just tried with one of my very large lists.
Jun
18
comment Print everything between two patterns, then delete first and last line of the resulting output
@StéphaneChazelas Thanks for that FAQ site, but -- that addresses a different problem, at least telling from the output (Contents of input.fil - Output of sed script). It will also print the lines preceding first pattern and following second pattern. Hence, that's not entirely the same...
Jun
18
comment Print everything between two patterns, then delete first and last line of the resulting output
@Cyrus Oops!! Good catch. Totally forgot to specify my output...
Jun
18
revised Print everything between two patterns, then delete first and last line of the resulting output
added 81 characters in body
Jun
18
comment Print everything between two patterns, then delete first and last line of the resulting output
@G-Man "Resulting output" refers to the output between the two pattern matches A and B (both of which I want to exclude). And from plain logic, what you get out will always have pattern A as first line and pattern B as the last, so a simple sed statement that does a d on first and last line will do.
Jun
18
comment Print everything between two patterns, then delete first and last line of the resulting output
Though this solution is very elegant, it gives a null string. :(( Have you actually tested your line?
Jun
18
comment Print everything between two patterns, then delete first and last line of the resulting output
+1 because of your great effort in explaining perl crypto-lingo to rookies ;-)
Jun
18
revised Print everything between two patterns, then delete first and last line of the resulting output
edited title
Jun
18
comment Print everything between two patterns, then delete first and last line of the resulting output
Yes, that's what I had assumed! That is, when I match between two patterns, that the 1d and $d will refer to the resulting output after I "filtered" the data by restricting the content between start_data and end_data, not the source file as-is.
Jun
18
asked Print everything between two patterns, then delete first and last line of the resulting output
Jun
17
comment Replacing new line character with a pipe and a new line character
May I also add that the ignoring of \n (et al) will even apply to their hexadecimal representation! That means in practice, that sed 's/someregex\x0a/something/' will fail as well, because sed will ignore the control character specified in hex in the regex. I had to learn this the hard way back then, when I had to debug the actual cause why my parser did not operate the expected way.
Jun
17
comment How to detect end of line with sed
Though I knew how to do that, you will get a +1 just for using the technical term for it. :) So this is called anchoring - nice to know. For up to now, I always had to paraphrase it... Another note about the + : you CAN use it even without using extended regex, just remember to write it like \+. So sed -e 's/[A-Za-z]\+$/replace/' file.txt will work perfectly even without GNU sed installed. And not to be forgotten: Do not use -E, as GNU sed does not support it.
Jun
17
revised history wiki excerpt
added "do not use" warning also in Excerpt. Warning must also appear when the user is too lazy to click on "learn more".
Jun
17
revised How to exclude command from history list, but to keep it in “live” history?
added 46 characters in body
Jun
17
revised How to exclude command from history list, but to keep it in “live” history?
Ugh, messed up HISTIGNORE line. Fixed.
Jun
17
suggested approved edit on history tag wiki excerpt
Jun
17
asked How to exclude command from history list, but to keep it in “live” history?
Jun
17
awarded  Popular Question
Jun
10
revised “history” stops working when run inside bash script
added 9 characters in body
Jun
8
revised “history” stops working when run inside bash script
Cosmetics: boldface looks better with a lone i than italic does :P