LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-03-2010, 11:35 AM   #1
kswapnadevi
LQ Newbie
 
Registered: Oct 2010
Posts: 16

Rep: Reputation: 0
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
 
Old 12-03-2010, 12:06 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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
 
1 members found this post helpful.
Old 12-03-2010, 12:57 PM   #3
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,596

Rep: Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570
Quote:
Originally Posted by kswapnadevi View Post
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.

Last edited by TB0ne; 12-03-2010 at 02:12 PM.
 
1 members found this post helpful.
Old 12-03-2010, 01:24 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
[SOLVED] Shell script to convert values on successive lines into consecutive ranges? kmkocot Programming 5 07-09-2010 10:59 AM
[SOLVED] Run script unless between time ranges scott_audio Linux - Newbie 5 08-08-2009 10:33 AM
Fixing Shell for Root user Jareka Linux - General 2 05-27-2007 11:56 AM


All times are GMT -5. The time now is 01:26 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration