Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've got some text that I'm operating on through a pipe, eg
cat - | grep "someString" | wc -l
On thing I'd like to do is weed out every other line.
Is there some way to do this?
I was thinking of somehow using sed and changing the separator to "", the telling it to run s,([^\n]\n)[^\n]\n,\1,
I've got some text that I'm operating on through a pipe, eg
cat - | grep "someString" | wc -l
On thing I'd like to do is weed out every other line.
Is there some way to do this?
I was thinking of somehow using sed and changing the separator to "", the telling it to run s,([^\n]\n)[^\n]\n,\1,
Not sure why you would want to just show every other line, however have you thought of looping:
Code:
cat - |grep "something"|while read l_line
do
# Perform a test of some sort before echoing!
echo $l_line
done
Suspecting homework therefore this is not a complete solution.
If this is not homework please explain why you want to show every other line (what this is for in a real world example)
Its not homework. I got output from a turn based game/program that shows the result of me vs opponent. Every other line is me, round next.
I want to count the occurances of a specific result of the me lines.
To flesh out your example, you could use a binary toggle to print every other time the loop runs.
Though if there was a course that taught this sort of stuff, I'd love to take it...
Quote:
Originally Posted by Tinkster
Way too complicated...
man sed
/step
Cheers,
Tink
Neat! Thanks!
I didn't even know you could search man (or less, I guess) like that!
One of these days, I'll have to learn sed/awk in detail.
Once on this topic, what about awk?
Does awk replace sed? Or do they have rather seperate uses?
Should I bother learn both? Which is better to learn?
Always depends on the complexity of the task at hand.
Think of awk as a missing link between sed and perl :}
As dgar said ... you could achieve the same result with
awk doing something like (mind you, I don't use an iterator).
awk '{if( NR%2 ){print}}'
The big difference is that awk has a concept of fields
which wasn't required in this instance. Plus it's quite
easy to use multi-line records in awk which can be very
tedious to deal with using sed.
For simpler tasks use the simpler tool (oversimplification).
It has a (marginally) smaller file-size and memory footprint,
so will commonly be somewhat quicker ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.