当前位置: 技术问答>linux和unix
急!!海外 求助 Shell script 小程序
来源: 互联网 发布时间:2015-11-10
本文导语: 各位高手! 我目前刚刚赴,美国留学, 我以前本科是学管理的.对编程不太熟悉, 最近学习UNIX 需要 用shell script 写些小程序 (实现功能简单的....只是 语法我不太会) 目前, 手边又...
各位高手!
我目前刚刚赴,美国留学, 我以前本科是学管理的.对编程不太熟悉, 最近学习UNIX 需要 用shell script 写些小程序 (实现功能简单的....只是 语法我不太会)
目前, 手边又没有可用的教材, 所以 问题虽然粗浅, 自己却是无法在规定时间内完成.
望各位帮帮忙!(如果可能, 回来在来拜谢)
这里有作业要求,并请加我的QQ 45353485, 或者MSN :ruiningcg@hotmail.com 我将把测试文件传给您!
原文:
The purpose of this assignment is to apply basic UNIX tools to a realistic data analysis task.
This assignment also uses data from the SyskillWebert.tar.gz file. Extracting from this file results in a directory SW that contains four subdirectories: Bands, BioMedical, Goats, and Sheep. Each of those subdirectories contains a number of files with names made up of digits and sometimes a "-" character (the "data files"), and one additional file named index that contains information about the data files in that subdirectory.
For each of the data files in the same subdirectory, an index file is supposed to contain one line of text with the following format:
file-name ¦ rating ¦ url ¦ date-rated ¦ title
where file-name is the name of the data file, rating is either "hot", "medium", or "cold", url is the URL of the rated web page (the HTML source code of which is in the corresponding data file), date-rated is the date on which that web page was rated, and title is the title of that web page. (Note: there are no spaces between the " ¦" characters and the fields they separate; and the other information is not supposed to contain any " ¦" characters.)
As it happens, the data and index files extracted from our copy of SyskillWebert.tar.gz contain a number of errors:
• At least one of the index files contains one or more lines of text that do not meet the format specification above.
• At least one of the directories contains one or more data files for which there are no corresponding lines in the index file.
• At least one of the directories contains one or more data files that are empty.
For this project you are to write a UNIX shell script that performs a series of reasonableness checks on a single SW subdirectory and its contents. (Thus you could run this shell script on each of the four subdirectories in turn, to check the entire data set.) You may use Ruby, Isis, Knoppix, or any other UNIX system. Your deliverables for this project are the following:
• a copy of your shell script, as an attached .TXT file; and
• a brief explanation of how to use your shell script
-- emailed to me by midnight on the due date. I will read your script, test it on a copy of the SyskillWebert data, and test it on other data as necessary to check its required behavior.
Your shell script must perform the following checks on a SyskillWebert-format directory. (I'd suggest requiring the user to cd into the directory of interest and run the script there, but the exact scenario of how to run your script is up to you.)
• Test for the presence of a file named index. If there is no such object, or if there is something named index but it's not a regular file, write out an error message to that effect and terminate processing.
• If there is a file named index, check each line of the file to see whether it consists of 5 fields separated by " ¦" characters.
o If a line is not in the 5-field format, write out an error message to that effect and continue processing the other lines of the index file.
o If a line is in the 5-field format, also check that:
The first field is the name of an object in this directory;
If there is such an object, it is a regular data file (i.e., not a directory or other special file system object);
If there is such a file, it is not empty (i.e., contains more than 0 bytes);
The second field is either "hot", "medium", or "cold";
(If any of these tests find an error, write out a message to that effect and continue with the other tests.)
• For each file in the directory other than index, check that the name of this file appears as the first field in some correctly formatted line of the index file.
主体译文:
一个文件--SyskillWebert.tar.gz ,包括4个子文件夹Bands, BioMedical, Goats, 和 Sheep.这些子文件夹里有很多文件,其中有一个叫index(索引)文件 它的格式如下:
file-name ¦ rating ¦ url ¦ date-rated ¦ title
这是个目录文件, file name是指文件名, rating 可能是"hot", "medium",或者"cold里面任意一个字符(表示文件的等级) URL 是网页链接 ………
这里 "¦" 和其它字母之间没有空格
做这个程序的目的是要写一个shell script 来检查 SW(解压后的文件夹,它包含上面提到过的四个文件夹)里的每一个文件(在这里,我们仅仅在一个文件夹下完成就可以了).
一. 测试这个这个文件夹里是否有index这个对象, 没有的话,中断全部程序报错, 有的话,继续检查.---它是否是个文件(而不是目录), 是目录中断全部程序, 是文件就进行下步
二.
1.测试这个index里面的每一行是否符合上面的文件格式(有4个"¦” 分割成5个区域),没有符合的就报错,然后继续执行下面
2. 检查每一行的"file name",看看是否在这个文件夹里(目前所在的子文件夹)有相应名称的文件,没有的话就报错,有就继续,
3.如果找到了这个相应名称的对象, 那么它是否是个文件(而非目录), 如果是目录那么报错, 如果是文件那么就继续
4.如果确定它是个文件, 那么检查是否为空, 为空报错并继续,
5.检查index每一行中的第二个区域(即格式中的rating)是否仅仅由”hot", "medium", or "cold” 组成.
如果还有别的字符就报错,然后继续
三, 检查这个子文件夹里的所有文件名(除了index), 是否文件名也是index里面那些已经核查过的正确格式行的(前面检查过的,分割成5个区域的为正确) file name , 不是的话报错
我目前刚刚赴,美国留学, 我以前本科是学管理的.对编程不太熟悉, 最近学习UNIX 需要 用shell script 写些小程序 (实现功能简单的....只是 语法我不太会)
目前, 手边又没有可用的教材, 所以 问题虽然粗浅, 自己却是无法在规定时间内完成.
望各位帮帮忙!(如果可能, 回来在来拜谢)
这里有作业要求,并请加我的QQ 45353485, 或者MSN :ruiningcg@hotmail.com 我将把测试文件传给您!
原文:
The purpose of this assignment is to apply basic UNIX tools to a realistic data analysis task.
This assignment also uses data from the SyskillWebert.tar.gz file. Extracting from this file results in a directory SW that contains four subdirectories: Bands, BioMedical, Goats, and Sheep. Each of those subdirectories contains a number of files with names made up of digits and sometimes a "-" character (the "data files"), and one additional file named index that contains information about the data files in that subdirectory.
For each of the data files in the same subdirectory, an index file is supposed to contain one line of text with the following format:
file-name ¦ rating ¦ url ¦ date-rated ¦ title
where file-name is the name of the data file, rating is either "hot", "medium", or "cold", url is the URL of the rated web page (the HTML source code of which is in the corresponding data file), date-rated is the date on which that web page was rated, and title is the title of that web page. (Note: there are no spaces between the " ¦" characters and the fields they separate; and the other information is not supposed to contain any " ¦" characters.)
As it happens, the data and index files extracted from our copy of SyskillWebert.tar.gz contain a number of errors:
• At least one of the index files contains one or more lines of text that do not meet the format specification above.
• At least one of the directories contains one or more data files for which there are no corresponding lines in the index file.
• At least one of the directories contains one or more data files that are empty.
For this project you are to write a UNIX shell script that performs a series of reasonableness checks on a single SW subdirectory and its contents. (Thus you could run this shell script on each of the four subdirectories in turn, to check the entire data set.) You may use Ruby, Isis, Knoppix, or any other UNIX system. Your deliverables for this project are the following:
• a copy of your shell script, as an attached .TXT file; and
• a brief explanation of how to use your shell script
-- emailed to me by midnight on the due date. I will read your script, test it on a copy of the SyskillWebert data, and test it on other data as necessary to check its required behavior.
Your shell script must perform the following checks on a SyskillWebert-format directory. (I'd suggest requiring the user to cd into the directory of interest and run the script there, but the exact scenario of how to run your script is up to you.)
• Test for the presence of a file named index. If there is no such object, or if there is something named index but it's not a regular file, write out an error message to that effect and terminate processing.
• If there is a file named index, check each line of the file to see whether it consists of 5 fields separated by " ¦" characters.
o If a line is not in the 5-field format, write out an error message to that effect and continue processing the other lines of the index file.
o If a line is in the 5-field format, also check that:
The first field is the name of an object in this directory;
If there is such an object, it is a regular data file (i.e., not a directory or other special file system object);
If there is such a file, it is not empty (i.e., contains more than 0 bytes);
The second field is either "hot", "medium", or "cold";
(If any of these tests find an error, write out a message to that effect and continue with the other tests.)
• For each file in the directory other than index, check that the name of this file appears as the first field in some correctly formatted line of the index file.
主体译文:
一个文件--SyskillWebert.tar.gz ,包括4个子文件夹Bands, BioMedical, Goats, 和 Sheep.这些子文件夹里有很多文件,其中有一个叫index(索引)文件 它的格式如下:
file-name ¦ rating ¦ url ¦ date-rated ¦ title
这是个目录文件, file name是指文件名, rating 可能是"hot", "medium",或者"cold里面任意一个字符(表示文件的等级) URL 是网页链接 ………
这里 "¦" 和其它字母之间没有空格
做这个程序的目的是要写一个shell script 来检查 SW(解压后的文件夹,它包含上面提到过的四个文件夹)里的每一个文件(在这里,我们仅仅在一个文件夹下完成就可以了).
一. 测试这个这个文件夹里是否有index这个对象, 没有的话,中断全部程序报错, 有的话,继续检查.---它是否是个文件(而不是目录), 是目录中断全部程序, 是文件就进行下步
二.
1.测试这个index里面的每一行是否符合上面的文件格式(有4个"¦” 分割成5个区域),没有符合的就报错,然后继续执行下面
2. 检查每一行的"file name",看看是否在这个文件夹里(目前所在的子文件夹)有相应名称的文件,没有的话就报错,有就继续,
3.如果找到了这个相应名称的对象, 那么它是否是个文件(而非目录), 如果是目录那么报错, 如果是文件那么就继续
4.如果确定它是个文件, 那么检查是否为空, 为空报错并继续,
5.检查index每一行中的第二个区域(即格式中的rating)是否仅仅由”hot", "medium", or "cold” 组成.
如果还有别的字符就报错,然后继续
三, 检查这个子文件夹里的所有文件名(除了index), 是否文件名也是index里面那些已经核查过的正确格式行的(前面检查过的,分割成5个区域的为正确) file name , 不是的话报错
|
man bash
|
看来大家都不容易啊
|
不会,帮你顶
|
english 太差,本事也差劲,老兄帮不上忙呀。
|
谢谢上面的兄弟了。。
好辛苦啊!~
我还要做Database 的作业
这个还没弄好!!
现在已经凌晨1:00了...
好辛苦啊!~
我还要做Database 的作业
这个还没弄好!!
现在已经凌晨1:00了...