Tenth Line

Shell脚本读取文件特定行

题目大意:给一个多行的文件,让你写一段shell脚本把文件的第10行输出来。

方法一:

# Read from the file file.txt and output the tenth line to stdout.
count=0
while read line && [ $count -le 10 ]
do
    count=$[$count+1]
    if [ $count -eq 10 ]
    then
        echo $line
        exit
    fi
done < file.txt

方法二:

# Read from the file file.txt and output the tenth line to stdout.
sed -n '10p' file.txt

方法三:

# Read from the file file.txt and output the tenth line to stdout.
awk '{if(NR==10) print $0}' file.txt


方法四:(方法三的简化)

# Read from the file file.txt and output the tenth line to stdout.
awk 'NR==10' file.txt


Task 4: Print Election Results (4 marks) In order to allow transparent auditing, each simulated election must produce a printed paper trail. Write a function print_results(election_results, parties) You need to write a function that prints a summary certificate of each election round in a precise tabular format. Arguments: election_results: a list of round histories from the simulated election, as described in the previous task. parties: the ordered list of parties contesting the election. Returns: None Details: You may assume that all parties in election_results are valid parties in parties , and that there are no more than ten rounds in election_results. The formatting requirements for the certificate are extremely strict, ensure you follow the rules below precisely. The certificate must not exceed 80 characters in width (including borders and padding). The certificate starts and ends with a padding row. These consist of one border line and two blank lines. The entire certificate is bordered on all four sides with the character '= '. Between the padding rows is the election data in a tabular format. The tabular format consists of a single header column (containing the round numbers), and n data columns where n is the number of parties in parties The header column should be left aligned and seven characters wide. All data should be the same width (c): c should be equal to the width of the longest unabbreviated party name, if this does not cause the certificate to exceed the width limit (80 chars). If it does cause the certificate to exceed the width limit, c should instead be the largest integer such that the certificate remains within the limit. Between each column (and between the first and last column and the border), there should be a single space. This is not counted in the column widths above. The history is then printed in a series of rows, one header row and m data rows where m is the number of rounds in election_results. The header row consists of a single line with: "Round:" in the header column (left aligned) The party names in the data columns (left aligned) Each party name which is longer than c should be abbreviated by taking the first character of each word, where word is defined by any sequence of characters separated by spaces. You may assume this abbreviation is unique, and fits in the required width. Other party names should be unchanged. Each data row consists of two lines: In the header column (left aligned): the first line should have number of the round (e.g. "Second"), and the second line should be blank. In the data columns (all right aligned): the first line should have the number of votes assigned to that party in that round as an integer. You may assume this always fits within the column width. the second line should display the first c characters of "eliminated" if that party was eliminated in that round, otherwise it should be blank. Between each non-padding row should be a single blank line.
10-17
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值