help with shell script

February 16, 2009 at 17:29:40
Specs: Macintosh
I have a file which has the following structure:
>sequence1
ACGUCGGAUCUGACUGUAUCG
>sequence2
ACGGUAUGUCUGUAUCUGUAUUCUG
>sequence3
ACGUAUCUAUCGUAUCUGAUC
...

I would like to extract only the first 15 characters of the lines that do NOT start with '>'.
Can anyone help me?
THANX!


See More: help with shell script

Report •


#1
February 17, 2009 at 06:58:05
I'm not a MAC guy, but this should give you a place to start. You might also have to use egrep:

#!/bin/ksh

rm -f datafile.tmp
grep -v '^>' datafile > datafile.tmp

while read line
do
   nl=$(echo "$line"|cut -c1-15)
   echo "$nl"
done < datafile.tmp


Report •

#2
February 17, 2009 at 08:09:33
Or, instead of a shell script, you can use a simple perl command.

perl -ne 'print $1,$/ if /^([A-Z]{15})/' filename


Report •

Related Solutions


Ask Question