Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6710715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:03:14+00:00 2026-05-26T08:03:14+00:00

i have a file and would like to copy some entries that satisfy certain

  • 0

i have a file and would like to copy some entries that satisfy certain conditions.
For example

myfile
chr1 a b c
chr2 a b c
chr3 x y z

I would like to copy lines whose first column starts with chr1 and i want to copy it n times.

myfile
chr1 a b c
chr1 a b c
chr1 a b c
chr2 a b c
chr3 x y z
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:03:15+00:00Added an answer on May 26, 2026 at 8:03 am

    Something like this would be fine?

    awk '{if ($1 == "chr1"){print; print;} print;}'

    It will print 2 more times the lines that start with chr1

    …and with a for loop:

    awk '{if ($1 == "chr1"){ for(i=1;i<=2;i++){ print; } } print;}'

    ok, this should be it

    #!/usr/bin/awk -f
    
    BEGIN{
        while ((getline < "conditions") > 0){
            cond[$1] = $2
        }
    }
    {
        print;
        for (i=0; i<cond[$1]; ++i){
            print;
        }
    }
    

    given a file named “conditions” like this:

    chr1 5
    chr2 3
    

    and your example (with chr1, chr2 etc on different lines) as an input

    it’ll print the chr1 line 6 times, the chr2 line 4 times and the chr3 line 1 time

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have text file with some stuff that i would like to put into
I have an XML file that I would like to map some attributes of
I have a jar file that I would like to execute using PHP, but
I have a binary file that I would like to regex search/replace hex bytes
I have a file that contain huge number of net names. I would like
I have an existing XML file that I would like to append without changing
I would like to replace every line that starts with a certain expression (example:
I would like some kind of delete/copy/move/etc Windows commands that completely ignores if a
I have a text file with some data i would like to open the
I have one file in my project, (the readme file,) which I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.