LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   fixing ranges using shell script (https://www.linuxquestions.org/questions/linux-newbie-8/fixing-ranges-using-shell-script-848188/)

kswapnadevi 12-03-2010 11:35 AM

fixing ranges using shell script
 
I have the datafile like this. I have to subtract 20 to the left of that number and add 120 to the right of that number. Output also given. Shell scripting for this highly appreciated. THANKS IN ADVANCE.

Quote:

Input:
Chr5:26236044-26236064
Chr25:2622227-2622247
Chr10:23813153-23813173
ChrX:62081599-62081619

Output:
Chr5:26236024-26236184
Chr25:2622207-2622367
Chr10:23813133-23813293
ChrX:62081579-62081739

catkin 12-03-2010 12:06 PM

Code:

#! /bin/bash

while read line
do
    chr=${line%%:*}
    line=${line#*:}
    n1=${line%-*}
    n2=${line#*-}
    let n1=n1-20
    let n2=n2+120
    echo "$chr:$n1-$n2"
done < input.txt


TB0ne 12-03-2010 12:57 PM

Quote:

Originally Posted by kswapnadevi (Post 4179672)
I have the datafile like this. I have to subtract 20 to the left of that number and add 120 to the right of that number. Output also given. Shell scripting for this highly appreciated. THANKS IN ADVANCE.

Can you not EVER try to do any of this on your own?? EVERY thread you've ever opened, you ask other folks to do your scripting/work for you. It would be nice if you showed some effort on your part, every now and then.

EDIT: Per the OP's private comment: You have said you are "new to shell" in EVERY thread. You can only be "new", if you don't ever TRY to do it yourself and learn.

colucix 12-03-2010 01:24 PM

This is almost the same problem shown in this other thread of yours: http://www.linuxquestions.org/questi...ipting-847987/. I agree with TB0ne: you should try to elaborate the given answers and try to do it by yourself. You will not find compliant people every time you ask someone to do the job for you!


All times are GMT -5. The time now is 04:13 AM.