Welcome to the Linux Foundation Forum!

Linux Command - split single line into multiple lines

My content of my input file - gene.data look like this:

tang 123 gene gene 3000 1000 4000

where

the 1st column is the name of the gene

the 2nd column is the id of the gene

the 3rd and 4th column are the type of sequence

the 5h column is the size of the gene in base pair.

the 6th column is the starting point of the gene location;

the 7th column is the end point of the gene location.

I would like to divide this line into multiple lines of 600 base pairs each until/before the ending point.

i want the result like this:

tang 123 gene gene 600 1000 1600

tang 123 gene gene 600 1600 2200

tang 123 gene gene 600 2200 2800

tang 123 gene gene 600 2200 2800

tang 123 gene gene 600 2800 3400

tang 123 gene gene 600 3400 4000

what should I do in order to come out these result? can I just write a command line or need to write a script?

Comments

  • bofhorg
    bofhorg Posts: 11
    edited September 2014
    you can probably do something like this:

    FILE=gene.data ; SPLIT=600 ; START=$(cat $FILE | awk '{print $6}') ; END=$(cat $FILE | awk '{print $7}') ; STATIC=$(cat $FILE | awk '{print $1" " $2" " $3" " $4}') ; while [ $START -lt $END ] ; do echo "$STATIC" $SPLIT "$START $(($START+$SPLIT))" ; START=$(($START+$SPLIT)) ; done

Categories

Upcoming Training