2011-11-22 58 views
0

我使用bash脚本需要其电网从X更改战舰游戏 - d

的目的是显示从测试文件输出到网格样式的程序。

以我output.txt的其上存储直到$ l为A1,A2,A3,A4,C1,C2

我有一个函数,低于该将显示以下

mark_seat() {

# Called by display_seats 
if [ $(echo "$1" | grep -c "$2$3") -gt 0 ] 
then  

    echo -en '\E[1;35mX\E[0m' 
     set_colwidth "" 5 

else 

     set_colwidth "" 6 
fi 

}

如果无法在我的$ L来检测类似的数据,它会给出一个空间,如下图所示。

我的问题是能够设定C1,C2作为破坏者船因此当它显示输出,则显示“d”而不是“X”。

http://www.flickr.com/photos/[email protected]/6381735021/

+0

您如何知道它是从原始数据的破坏者? Bash可以做的if/else块,这样你就可以与像你原来的输出额外的条款做到这一点。 –

回答

0

你可以用字符串操作做到这一点

假设位置存储这样一个字符串代表一行

A_ROW="____X_____" 
echo ${A_ROW:0:4}D${A_ROW:5:4} 
____D_____ 

然而,也有窍门能让角色的连续排名

ASTRING="abcdefg" 
POS_d=${ASTRING%d*} 
echo position of d is ${#POS_d} 
#note that POS_d is actually the string abc and ${#POS_d} is the length of abc 
#since values start at 0, this is the position of d 
#if you have multiple occurrences you can do this multiple times