user2300940
user2300940

Reputation: 2385

Rearrange lines to tabular format

I would like to grab the part after "-" and combine it with the following letter-string into a tab-output. I tried something like cut -d "*-" -f 2 <<< "$your_str" but I am not sure how to do the whole shuffling.

Input:

>1-395652
TATTGCACTTGTCCCGGCCTGT
>2-369990
TATTGCACTCGTCCCGGCCTCC
>3-132234
TATTGCACTCGTCCCGGCCTC
>4-122014
TATTGCACTTGTCCCGGCCTGTAA
>5-118616

Output:

TATTGCACTTGTCCCGGCCTGT 395652
TATTGCACTCGTCCCGGCCTCC 369990

Upvotes: 1

Views: 48

Answers (3)

agc
agc

Reputation: 8406

Portable sed:

sed -n 's/.*-//;x;n;G;s/\n/ /p' inputfile

Output:

TATTGCACTTGTCCCGGCCTGT 395652
TATTGCACTCGTCCCGGCCTCC 369990
TATTGCACTCGTCCCGGCCTC 132234
TATTGCACTTGTCCCGGCCTGTAA 122014

Upvotes: 1

Cyrus
Cyrus

Reputation: 88553

With GNU sed:

sed -nE 'N;s/.*-([0-9]+)\n(.*)/\2\t\1/p' file

Output:

TATTGCACTTGTCCCGGCCTGT  395652
TATTGCACTCGTCCCGGCCTCC  369990
TATTGCACTCGTCCCGGCCTC   132234
TATTGCACTTGTCCCGGCCTGTAA        122014

Upvotes: 1

karakfa
karakfa

Reputation: 67467

awk to the rescue!

awk -F- '/^>/{k=$2; next} {print $0, k}' file

Upvotes: 3

Related Questions