# Reading expression problem

**URL:** <https://community.unix.com/t/reading-expression-problem/274775>\
**Category:** Shell Programming and Scripting\
**Created:** [October 5, 2010, 10:42pm UTC](https://community.unix.com/t/reading-expression-problem/274775 "2010-10-05T22:42:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hravisankar](https://community.unix.com/letter_avatar/hravisankar/32/6_22734026db12803ebb3e059622ac3534.png) [@hravisankar](https://community.unix.com/u/hravisankar)\
**Post date:** [October 5, 2010, 10:42pm UTC](https://community.unix.com/t/reading-expression-problem/274775/1 "2010-10-05T22:42:45Z")

</div>

I want to read a file -line by line which consists of the following statements  
Chr18:4000-4010  
Chr20:4020-4030  
Chr15:8000-8050

Pls. give a expression to read the line like this from a file

Chr18:4000-4010

the given two replies reading like that

Chr18:-10

but it is important to read like Chr18:40000-400010 from a file

Pls. help me

because it is important to run a tool in computational biology

pls. help me to correct this.

---

<div class="post-metadata">

**Author:** ![kurumi](https://community.unix.com/letter_avatar/kurumi/32/6_22734026db12803ebb3e059622ac3534.png) [@kurumi](https://community.unix.com/u/kurumi)\
**Post date:** [October 5, 2010, 10:54pm UTC](https://community.unix.com/t/reading-expression-problem/274775/2 "2010-10-05T22:54:41Z")

</div>

```nohighlight
$ ruby -F"[:-]" -ane 'print "#{$F[0]}:#{$F[1].to_i - $F[2].to_i}\n"' file
Chr18:-10
Chr20:-10
Chr15:-50

```

---

<div class="post-metadata">

**Author:** ![durden\_tyler](https://community.unix.com/user_avatar/community.unix.com/durden_tyler/32/1450_2.png) [@durden\_tyler](https://community.unix.com/u/durden_tyler)\
**Post date:** [October 6, 2010, 12:36am UTC](https://community.unix.com/t/reading-expression-problem/274775/3 "2010-10-06T00:36:14Z")

</div>

```nohighlight
$ 
$ 
$ cat f23
Chr18:4000-4010
Chr20:4020-4030
Chr15:8000-8050
$ 
$ awk -F[:-] '{print $1":"$2-$3}' f23
Chr18:-10
Chr20:-10
Chr15:-50
$ 
$ perl -F[:-] -lane 'print "$F[0]:",$F[1]-$F[2]' f23
Chr18:-10
Chr20:-10
Chr15:-50
$ 
$ 

```

tyler\_durden
