0

This question already has an answer here:

The below has actually been asked before, which I hadn’t realised. but out of curiosity, how would you go about it if you wanted not just odds or evens, for example every 5th line

I'm trying to copy every 2nd line from a text file starting from 1 e.g. lines: 1,3,5,7,9,11,13,15,17,19,21.....

Here is an example of an input and desired output file:

Input (note that the long list of varying ATC's and G's a are actually one line)

M00629_17_000000000-AC1KF_1_1101_15379_1548
TACCGGCAGCACGAGTGATAGCCACTTTTATTGGGCCTAAAGCGTCCGTAGCCGGCCGAACAGGTCCGTCGGGAAATCCACCCGCCCAACGGGTGGGCGTCCGGCGGAAACCGGTCGGCTTGGGACCGGGAGACCAGAGGGGTACGTCGAGGGTAGGAGTGAAATCCCGTAATCCTCGACGGACCGCCGGTAGCGAAAGCGCCTCTGGAGAACGGATCCGACGGTGAGGGACGAAAGCTTGGGTCTCGAACCGG
M00629_17_000000000-AC1KF_1_1101_19167_1966
TACCGGCAGCACGAGTGATAGCCACTTTTATTGGGCCTAAAGCGTCCGTAGCCGGCCGAACAGGTCCGTCGGGAAATCCACCCGCCCAACGGGTGGGCGTCCGGCGGAAACCAGTCGGCTTGGGACCGGGAGACCAGAGGGGTACGTCGAGGGTAGGAGTGAAATCCCGTAATCCTCGACGGACCGCCGGTAGCGAAAGCGCCTCTGGAGAACGGATCCGACGGTGAGGGACGAAAGCTTGGGTCTCGAACCGG
M00629_17_000000000-AC1KF_1_1101_19168_1991
TACCGGCAGCACGAGTGATAGCCACTTTTATTGGGCCTAAAGCGTCCGTAGCCGGCCGAACAGGTCCGTCGGGAAATCCACCCGCCCAACGGGTGGGCGTCCGGCGGAAACCAGTCGGCTTGGTACCGGGAGACCAGAGGGGTACGTCGAGGGTAGGAGTNAAATCCCGTAATCCTCGACGGACCGCCGGTAGCGAAAGCGCCTCTGGAGAACGGATCCGACGGTGAGGGACGAAAGCTTGGGTCTCGAANCGG
M00629_17_000000000-AC1KF_1_1101_14117_2215
TACCGGCAGCACGAGTGATAGCCACTTTTATTGGGCCTAAAGCGTCCGTAGCCGGCCGAACAGGTCCGTCGGGAAATCCACCCGCCCAACGGGTGGGCGTCCGGCGGAAACCAGTCGGCTTGGGACCGGGAGACCAGAGGGGTACGTCGAGGGTAGGAGTGAAATCCCGTAATCCTCGACGGACCGCCGGTAGCGAAAGCGCCTCTGGAGAACGGATCCGACGGTGAGGGACGAAAGCTTGGGTCTCGAACCGG
M00629_17_000000000-AC1KF_1_1101_15116_2236
TACCGGCAGCACGAGTGATAGCCACTTTTATTGGGCCTAAAGCGTCCGTAGCCGGCCGAACAGGTCCGTCGGGAAATCCACCCGCCCAACGGGTGGGCGTCCGGCGGAAACCAGTCGGCTTGGGACCGGGAGACCAGAGGGGTACGTCGAGGGTAGGAGTGAAATCCCGTAATCCTCGACGGACCGCCGGTAGCGAAAGCGCCTCTGGAGAACGGATCCGACGGTGAGGGACGAAAGCTTGGGTCTCGAACCGG
M00629_17_000000000-AC1KF_1_1101_11619_2261
TACCGGCAGCACGAGTGATAGCCACTTTTATTGGGCCTAAAGCGTCCGTAGCCGGCCGAACAGGTCCGTCGGGAAATCCACCCGCCCAACGGGTGGGCGTCCGGCGGAAACCAGTCGGCTTGGGACCGGGAGACAAGAGGGGTACGTCGAGGGTAGGAGTGAAATCCCGTAATCCTCGANGGACCGCCGGTAGCGAAAGCGCCTCTGGAGAACGGNTCCGACGGTGAGGGNCGAAAGCTTGGGTCTCGAACCGG
M00629_17_000000000-AC1KF_1_1101_18647_2316

Output

M00629_17_000000000-AC1KF_1_1101_15379_1548
M00629_17_000000000-AC1KF_1_1101_19167_1966
M00629_17_000000000-AC1KF_1_1101_19168_1991
M00629_17_000000000-AC1KF_1_1101_14117_2215
M00629_17_000000000-AC1KF_1_1101_15116_2236
M00629_17_000000000-AC1KF_1_1101_11619_2261
M00629_17_000000000-AC1KF_1_1101_18647_2316

marked as duplicate by don_crissti, jasonwryan, Eric Renouf, Jeff Schaller, jimmij May 23 '16 at 0:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • this works perfectly for what I needed, thanks again. out of interest (as could have future practicality) how would you go about it if you weren't just grabbing odds or evens? for example every 5 lines? – Giles May 23 '16 at 0:23
  • sed -n '1~5p' and there are other ways... google is your friend: print every nth line – don_crissti May 23 '16 at 0:31
  • i think i was overly verbose when googling, and could perhaps have been more savvy with my search before pestering on this forum. I appreciate the quick reply and help, sorry for the poorly investigated question though. google has been a good friend and source of learning with much of my attempts at coding so far, and the coding community are really friendly, makes me want to get increasingly involved in scripting etc. – Giles May 23 '16 at 0:52

Browse other questions tagged or ask your own question.