Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to skip a line every two lines starting by skipping the first line?

Hey guys I need some help over here

here’s my code : ls -lt | sed -n 'p;n'

that code makes me skip from a line to another when listing file names but doesn’t start by skipping the first one, how to make that happen ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here’s an exemple without my code to skip to make it clear:

enter image description here

And here’s an exemple of when I use the skip code
enter image description here

>Solution :

You have to invert your sed command: it should be n;p instead of p;n:

Your code:

for x in {1..20}; do echo $x ; done | sed -n 'p;n'
1
3
5
7
9
11
13
15
17
19

The version with sed inverted:

for x in {1..20}; do echo $x ; done | sed -n 'n;p'

Output:

2
4
6
8
10
12
14
16
18
20
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading