using regex in bash like in perl?

sh/bash/dash/ksh/zsh等Shell脚本
回复
huwenhuo
帖子: 74
注册时间: 2008-01-10 11:14

using regex in bash like in perl?

#1

帖子 huwenhuo » 2008-06-03 13:30

"bash is awesome". that is a popular sentense

我的问题,:

1. 我以前用perl已经比较顺利了.
用 shell的时候, 在正则表达式的使用上遇上了难题.
比如在perl里, 可以用以下测试;

代码: 全选

if ($line=~/>/)#这样可以找出DNA序列文件, fasta格式中的头行
甚至

代码: 全选

if ($line=~/>(Os01g........)/)#可以找出基因的ID号$1
在shell里不知道有没有相应的命令.

2. 在perl里,经常读入一行文本, 然后用

代码: 全选

@row=split "\t", $line;
...get the fields i need,
...sometime edit the fields
...for example "134-341", which is split to $num1=134, and $num2=341 further,
...then i can use this position to get DNA sequence from the genome
...something like that
在bash里也没有找到相应的命令,

我看了grep, sed, awk, 也看了别人用eval, 显然这些都很能达到目的.

^_^[/list]
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#2

帖子 eexpress » 2008-06-03 19:10

☎ bash --version
GNU bash, version 3.2.33(1)-release (i486-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

一句话,就是判断的时候,什么 “ ‘ 都不需要。今天害我搞晕了的。

if [[ $1 =~ .*\-.* ]]; then
● 鸣学
回复