How can you show different lines with sed?

How can only lines 18,30,45,60 be displayed with the sed command?
Run this command (sed -n -e ‘18,30,45,60p’ example.txt) but show error

Does anyone know how to do it?

Is this your next homework-assignment? :nerd_face:

1 Like

sed -n '18p;30p;45p;60p' example.txt

2 Likes

Thank you very much

1 Like

It works, see my last post! :point_up:

1 Like

Sorry for editing the original description of the post

1 Like

Teacher to change the question, display lines from 1 to 40, then lines 51,58,61 should be displayed.

sed -n ‘1p…40p;51p;58p;61p’ example.txt

My command did not work
And we are not allowe to write lines from 1 to 40 one by one
Please

Should be sed -n ‘1p-40p;51p;58p;61p’ example.txt

With such a “strict teacher”, you should better learn to query the web properly at first, before diving any deeper into your lessons! :wink:

https://searx.be/search?q=sed%20show%20specific%20lines%20numbers%20inside%20a%20text&categories=general

:nerd_face:

1 Like

Thanks a lot
it was great
I search with duck duck go, unfortunately I can’t get good results

The search-engine used seems secondary, although I find searx.be the best for any computing-related stuff.

The search keywords are what really matters. You can gather them from the link above and see it is close to what your question was posted in this thread:

sed show specific lines numbers inside text file ...
1 Like

Output error not working

Don’t be so lazy now!

Look here, it is among the search-results I gave you (and study the text on that site):

1 Like

Why did you delete it?, but I saw it before deleting it
Thankful

sed -n ‘1,40p;51p;58p;61p’ example.txt

1 Like

Yeah it works. I deleted it because I made a mistake when first testing it myself, and then thinking it was wrong. :v:

1 Like

According to manpage
sed -n '1~40p;51p;58p;61p' Example.txt

Works just tried. :sweat_smile:

1 Like

I wanted to say something
My purpose of asking is not to become lazy, but to learn it well
and unfortunately my English is also weak
Thanks

1 Like

I wouldn’t even find that tilde-key " ~ " on my board, without hastle. Therefore comma " , " also works for line-ranges I guess. :wink:

2 Likes

That is perfectly fine. You’re welcome. :wink:

For any new “task”, please open a new thread.

Thank you. :v:

1 Like

manpages is also available for the most common languages.

See
pacman -Ss man-pages
and choose yours. :wink:

1 Like

Your solution is the right one.
Mine refers to lines with distances and does not show the required result.

I just wanted to play along for a moment. Sorry. :blush:

1 Like