LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1279|回复: 5

shell命令 基本使用,用不来真憋死人,

[复制链接]
发表于 2008-1-23 11:46:33 | 显示全部楼层 |阅读模式
keyword=$1
imagefilename=`cat /home/newman0708/doc/database/accessorylist.csv | grep $keyword `

我行不到想在结果,

就执行了cat部分的内容, grep部分好像没执行,不知道为什么,

请高手帮忙看一下,
发表于 2008-1-23 13:14:54 | 显示全部楼层
Post by newman0708;1810272
keyword=$1
imagefilename=`cat /home/newman0708/doc/database/accessorylist.csv | grep $keyword `

我行不到想在结果,

就执行了cat部分的内容, grep部分好像没执行,不知道为什么,

请高手帮忙看一下,



keyword=$1
csvfile=home/newman0708/doc/database/accessorylist.csv
grep $keyword   $csvfile > output.csv


imagefilename 这个相当于string 变量,而grep 出来的是文件类型,当然存储不了。
回复 支持 反对

使用道具 举报

发表于 2008-1-23 13:15:52 | 显示全部楼层
csvfile=home/newman0708/doc/database/accessorylist.csv
改为
csvfile=/home/newman0708/doc/database/accessorylist.csv
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-1-23 13:23:41 | 显示全部楼层
谢谢 各位,我的问题解决了。

下面是我的脚本:
showimage

#!/bin/sh
#show the image

#if the number of the argu is not only one ,quit the program
if [ $# -ne 1 ]; then
   exit 1
fi

#show the keyword
keyword=$1
echo $keyword

#parse the accessary Lists
imagefilename=`cat /home/newman0708/doc/database/accessorylist.csv |grep $keyword |awk -F "\t" '{gsub("\"","",$11);print "/home/newman0708/quickjump/AccessoryImages2/" $11 }'`

#show the details
cat /home/newman0708/doc/database/accessorylist.csv |grep $keyword

#show the image files
echo "show image: " $imagefilename

#gthumb view
gthumb $imagefilename
回复 支持 反对

使用道具 举报

发表于 2008-1-23 13:34:11 | 显示全部楼层
Post by newman0708;1810306
谢谢 各位,我的问题解决了。

下面是我的脚本:
showimage

#!/bin/sh
#show the image

#if the number of the argu is not only one ,quit the program
if [ $# -ne 1 ]; then
   exit 1
fi

#show the keyword
keyword=$1
echo $keyword

#parse the accessary Lists
imagefilename=`cat /home/newman0708/doc/database/accessorylist.csv |grep $keyword |awk -F "\t" '{gsub("\"","",$11);print "/home/newman0708/quickjump/AccessoryImages2/" $11 }'`

#show the details
cat /home/newman0708/doc/database/accessorylist.csv |grep $keyword

#show the image files
echo "show image: " $imagefilename

#gthumb view
gthumb $imagefilename




两处 cat 用的都多余
回复 支持 反对

使用道具 举报

发表于 2008-2-3 00:36:37 | 显示全部楼层
为什么不直接grep str file.txt
而要使用cat? 不解中...
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表