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 8952793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:57:11+00:00 2026-06-15T13:57:11+00:00

I have a huge file whose first line is: chr start end strand ref_context

  • 0

I have a huge file whose first line is:

chr start end strand ref_context repeat_masked s1_smpl_context s1_c_count s1_ct_count s1_non_ct_count s1_m% s1_score s1_snp s1_indels s2_smpl_context s2_c_count s2_ct_count s2_non_ct_count s2_m% s2_score s2_snp s2_indels s3_smpl_context s3_c_count s3_ct_count s3_non_ct_count s3_m% s3_score s3_snp s3_indels…

Up to s8.

I want to replace all instances of s1 to s4 with L1 to L4 and then all instances of s5 to s8 with W1 to W4.
Is it best to do this with grep or awk or some other way?

  • 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-06-15T13:57:12+00:00Added an answer on June 15, 2026 at 1:57 pm

    Replace s[1-4] with L[1-4] and s[5-8] with W[1-4] only on the first line in the file:

    sed -Ee '1s/s([1-4])/L\1/g' -e '1s/s([5-8])/W\1/g' -e '1y/5678/1234/' -e '1q' file
    

    Demo:

    $ cat file

    chr start end strand ref_context repeat_masked s1_smpl_context s1_c_count s1_ct_count s1_non_ct_count s1_m% s1_score s1_snp s1_indels s2_smpl_context s2_c_count s2_ct_count s2_non_ct_count s2_m% s2_score s2_snp s2_indels s3_smpl_context s3_c_count s3_ct_count s3_non_ct_count s3_m% s3_score s3_snp s3_indels s4_Smpl_context s4_c_count s4_ct_count s4_non_ct_count s4_m% s4_score s4_snp s4_indels s5_smpl_context s5_c_count s5_ct_count s5_non_ct_count s5_m% s5_score s5_snp s5_indels s6_smpl_context s6_c_count s6_ct_count s6_non_ct_count s6_m% s6_score s6_snp s6_indels s7_Smpl_context s7_c_count s7_ct_count s7_non_ct_count s7_m% s7_score s7_snp s7_indels s8_smpl_context s8_c_count s8_ct_count s8_non_ct_count s8_m% s8_score s8_snp s8_indels

    s1_line_2

    s3_line_3

    s8_line_4

    $ sed -Ee ‘1s/s([1-4])/L\1/g’ -e ‘1s/s([5-8])/W\1/g’ -e ‘1y/5678/1234/’ -e ‘1q’ file

    chr start end strand ref_context repeat_masked L1_smpl_context L1_c_count L1_ct_count L1_non_ct_count L1_m% L1_score L1_snp L1_indels L2_smpl_context L2_c_count L2_ct_count L2_non_ct_count L2_m% L2_score L2_snp L2_indels L3_smpl_context L3_c_count L3_ct_count L3_non_ct_count L3_m% L3_score L3_snp L3_indels L4_Smpl_context L4_c_count L4_ct_count L4_non_ct_count L4_m% L4_score L4_snp L4_indels W1_smpl_context W1_c_count W1_ct_count W1_non_ct_count W1_m% W1_score W1_snp W1_indels W2_smpl_context W2_c_count W2_ct_count W2_non_ct_count W2_m% W2_score W2_snp W2_indels W3_Smpl_context W3_c_count W3_ct_count W3_non_ct_count W3_m% W3_score W3_snp W3_indels W4_smpl_context W4_c_count W4_ct_count W4_non_ct_count W4_m% W4_score W4_snp W4_indels

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

Sidebar

Related Questions

I have a two huge text files whose format is as below. File 1:
I have a huge text file, each line seems like this: Some sort of
I have a huge file to read whose structure is: [...] (0,0,0,0,0): 5.00634e-33, 5.59393e-33,
I have a huge file which has two columns per line separated by tab.
I have a huge file that has some lines that need to have a
I have a huge file and need to read it and process. with open(source_filename)
I have a huge file (with around 200k inputs). The inputs are in the
I have a huge text file and I wanted to write a program which
I have a huge C file (~100k lines) which I need to be able
I have a huge CSV file with over 700K + lines. I have to

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.