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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:53:36+00:00 2026-06-13T19:53:36+00:00

Input: rs001 A C T G C G T T rs002 C C T

  • 0

Input:

rs001 A C T G C G T T
rs002 C C T T G G A A

out1:

rs001 AC TG CG TT
rs002 CC TT GG AA

out2 :

rs001 1 1 1 2
rs002 2 2 2 2

Ok so basically I want to replace any two similar nucleotides (like AA, CC, TT, or GG) to 2 and any two different (like AT, TA, CG, .. etc) to 1 taking into account that the input should be converted first to out1 then to out2. Also we have so many fields (like 200 columns) in each row, so loops are needed here.

This is what I tried:

cat input | awk '{ for (x = 2; x <= NF; x = x+2) print $x$(x+1) }'

Results are so weird, so can anyone please tell me why I can’t get out1 ?! What mistakes I did in awk loops ?

Thanks in advance

  • 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-13T19:53:37+00:00Added an answer on June 13, 2026 at 7:53 pm

    Here’s how you fix your awk script to get output 1:

    awk '{ printf "%s ", $1; for (x = 2; x <= NF; x = x + 2) {printf "%s%s ", $x, $(x+1)} printf "\n"}' input
    

    print adds a new line at the end by default, so you’ll have to use formatted strings printf to specify where exactly you want the new lines.

    (Also added printf "%s ", $1; at the start to print the header at the start of each line)

    Edit: Triplee’s solution looks much more elegant than mine – you should ditch awk and go with his =)

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

Sidebar

Related Questions

input is a string (var str) something like this: <<hello there//abcd//1234>> I want to
Input: Two 3d concave polygons A and B , unit vector d . No
Input : strings with date and optional time. Different representations would be nice but
Example input string: (F1 (F2 X (Y) Z) (F3 A B) What i want
input type=button name=colr value= Blue onclick=document.bgColor='#0000FF' Basically i have done buttons using javascipt to
Input >> list = [[1,2,3], [6], [3,4,5,6]] Output >> [1,2,3,3,4,5,6,6] I want to know
input is like this 5 // is # of vertices 1 1 0 1
Input: I want to remove double space from textbox. Output: I want to remove
Input string is something like this: OU=TEST:This001. We need extra This001. Best in C#.
Input : Hello my name is X . Blah Blah Blah EDIT 1: Any

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.