0
/home/msabbar/sample_dir2
`-- sample_dir
    |-- admin
    |-- cambridge
    |   |-- cafeteria
    |   |-- library
    |   `-- security
    |       |-- annex
    |       |-- building
    |       `-- parking
    |-- faculty
    |-- history.exe
    |-- markham
    |   |-- annex
    |   |-- building1
    |   `-- parking
    `-- stenton
        |-- gen_ed
        |   |-- Holidays
        |   `-- cars2
        |-- lib_arts
        |   |-- english.txt
        |   `-- match.doc
        `-- phone_directory

11 个目录,12 个文件

您当前的目录是 sample_dir。显示文件 cars2 的第 2 行,转换为大写(提示:以 'head' 命令开头):

好吧,我做到了

head -2 | tr "[a-z]" "[A-Z]" < stenton/gen_ed/cars2

head -n 2 | tr "[a-z]" "[A-Z]" < stenton/gen_ed/cars2

但这是错误的

我在这里做错了什么?

4

2 回答 2

2

我想你想做:

 head -2 your_file | tail -1 | tr "[a-z]" "[A-Z]"
于 2013-03-11T00:36:18.980 回答
1

我可以忽略提示吗(我猜是你的作业)?

awk 'NR==2 {print toupper($0);exit}' stenton/gen_ed/cars2

或者

sed -n 'n;s/.*/\U&/p;q' stenton/gen_ed/cars2
于 2013-03-11T00:36:24.923 回答