0

I want to do tsv file processing using awk, Here's my input:

scaffold1   1   100 
scaffold1   101 200
scaffold1   201 300
scaffold2   1   100
scaffold2   201 500
scaffold3   10  500
scaffold4   10  300

Desired_output:

Feature scaffold1
1   100
101 200
201 300
Feature scaffold2
1   100
01  500
Feature scaffold3
10  500
Feature scaffold4
10  300

I tried using uniq and sort and also awk for printing uniq of first column using command awk '!seen[$1]++ Input.txt but it prints all unique values from first column and then i can print rest of the columns, but i want to print first unique value and rest columns in the next line, as shown above.

Please tell me is there a way to do this?

2

Using awk:

awk '!seen[$1]++ {print "Feature",$1} {print $2,$3}' file
Feature scaffold1
1 100
101 200
201 300
Feature scaffold2
1 100
201 500
Feature scaffold3
10 500
Feature scaffold4
10 300
| improve this answer | |
0

i Have done this by using combination of sed and awk tested and its works fine

code:


for o in `awk '{print $1}' example.txt| sort | uniq `; do sed -n "/$o/p" example.txt | sed "s/$o//g" |sed "1i Feature $o"; done  

output


Feature  scaffold1
 1   100
  101 200
  201 300
Feature  scaffold2
  1   100
  201 500
Feature  scaffold3
  10  500
Feature  scaffold4
  10  300

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.