由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - my homework for UNIX shell高手, thanks!!!
相关主题
question看看下面这个至少要多少行
哪里有MATLAB下载,谢谢![转载] Re: shell script question
Re: HELP PLS!help shell script (waiting on line)
Re: 为什么emacs自动给我加^M.[转载] 问个shell怎么写?
有关Unix shell script的问题unix command explain??
一个关于命令行的小问题急,帮个忙
如何显示出“*”One shell question
Shell QuestionShell script求教
相关话题的讨论汇总
话题: mr话题: hobbies话题: loves话题: table话题: unix
进入Unix版参与讨论
1 (共1页)
a*******n
发帖数: 2
1
how to access a table in file, e.g.
A FILE called "hobbies", with contents:
zhang3, fishing
li4, playing basketball
wang5, watching TV
...
how to write a shell program "table", can handle a table like "hobbies"
$ table hobbies
Mr. zhang3 loves fishing;
Mr. li4 loves playing basketball;
Mr. wang5 loves watching TV;
...
p******f
发帖数: 162
2

if perl is allowed...
#!perl -p
s/^/Mr. / && s/,/ loving/ && s/$/;/ or die "data format error"

【在 a*******n 的大作中提到】
: how to access a table in file, e.g.
: A FILE called "hobbies", with contents:
: zhang3, fishing
: li4, playing basketball
: wang5, watching TV
: ...
: how to write a shell program "table", can handle a table like "hobbies"
: $ table hobbies
: Mr. zhang3 loves fishing;
: Mr. li4 loves playing basketball;

a*******s
发帖数: 324
3


【在 a*******n 的大作中提到】
: how to access a table in file, e.g.
: A FILE called "hobbies", with contents:
: zhang3, fishing
: li4, playing basketball
: wang5, watching TV
: ...
: how to write a shell program "table", can handle a table like "hobbies"
: $ table hobbies
: Mr. zhang3 loves fishing;
: Mr. li4 loves playing basketball;

d*****g
发帖数: 36
4
#!/bin/sh
cat $1 | while read line; do
NAME="`echo $line | cut -d, -f1`"
HOBBIE="`echo $line | cut -d, -f2`"
echo "Mr. $NAME loves $HOBBIE"
done
or
#!/bin/sh
cat $1 | while read line; do
echo "Mr. `echo $line | cut -d, -f1` loves `echo $line | cut -d, -f2`"
done

【在 a*******s 的大作中提到】

a*******n
发帖数: 2
5
Thanks!
高手高手..

【在 d*****g 的大作中提到】
: #!/bin/sh
: cat $1 | while read line; do
: NAME="`echo $line | cut -d, -f1`"
: HOBBIE="`echo $line | cut -d, -f2`"
: echo "Mr. $NAME loves $HOBBIE"
: done
: or
: #!/bin/sh
: cat $1 | while read line; do
: echo "Mr. `echo $line | cut -d, -f1` loves `echo $line | cut -d, -f2`"

k*j
发帖数: 2
6
Another approach:
#!/bin/sh
sed -e 's/\(.*\), *\(.*\)/Mr. \1 loves \2;/' $1

-f2`"
"hobbies"

【在 a*******n 的大作中提到】
: Thanks!
: 高手高手..

f*****r
发帖数: 229
7
awk -F, '{printf "Mr. %s loves %s;\n",$1,$2}' hobbies > table

【在 a*******n 的大作中提到】
: how to access a table in file, e.g.
: A FILE called "hobbies", with contents:
: zhang3, fishing
: li4, playing basketball
: wang5, watching TV
: ...
: how to write a shell program "table", can handle a table like "hobbies"
: $ table hobbies
: Mr. zhang3 loves fishing;
: Mr. li4 loves playing basketball;

1 (共1页)
进入Unix版参与讨论
相关主题
Shell script求教有关Unix shell script的问题
新手求助shell script一个关于命令行的小问题
UNIX SHELL 下中文如何显示出“*”
Shell ScriptShell Question
question看看下面这个至少要多少行
哪里有MATLAB下载,谢谢![转载] Re: shell script question
Re: HELP PLS!help shell script (waiting on line)
Re: 为什么emacs自动给我加^M.[转载] 问个shell怎么写?
相关话题的讨论汇总
话题: mr话题: hobbies话题: loves话题: table话题: unix