# Assignment 2

AI悦创原创Python 一对一教学SCU CSSanta Clara University圣克拉拉大学Python 一对一教学SCU CSSanta Clara University圣克拉拉大学大约 3 分钟...约 871 字

## Instructions:

Write the commands needed to solve the following exercises on mis01.scu.eduopen in new window. Do not worry about upper/lower case.

## Problem 1

First, make a directory temp inside your personal directory. Then, position yourself in directory temp. Use relative pathnames to copy into temp all of the files in `/home/OMIS107/HW2` whose name ends with 120, 121, 122, ..., up to 180 included. (one or two cp commands)

### Solution with two commands

``````cp ../../OMIS107/HW2/*1[2-7][0-9] .
cp ../../OMIS107/HW2/*180 .
``````

### Solution with one command

``````cp ../../OMIS107/HW2/*180 ../../OMIS107/HW2/*1[2-7][0-9] .
``````

## Problem 2

Position yourself in `/home/OMIS107/Lecture2`. Print the lines of alice.txt where the word “Alice” appears shortly before an exclamation point. Here, we say that Alice appears “shortly” before an exclamation mark if there are at most 7 other characters between the “e” of Alice and “!”.

### Solution

``````grep -Ein "\bAlice.?.?.?.?.?.?.?!" alice.txt
grep -Ein "alice.?.?.?.?.?.?.?!" alice.txt
grep -Ein "alice.{0,7}!" alice.txt
grep -Ein "alice.{,7}!" alice.txt
``````

## Problem 3

Position yourself in /home/OMIS107/Lecture2. Print the lines of alice.txt that contain the string “form” as part of a longer word.

Examples of line to retrieve:

“我需要更多的信息。”

• “Who did you inform about it?”

“你向谁通报了这件事？”

• “Nice formation”

“好的阵型”

Example of line NOT to retrieve: “you first form a line” (form is not part of a longer word)

``````grep -Ein "[a-z]form|form[a-z]" alice.txt
grep -Ein "[a-z]+form|form[a-z]+" alice.txt
grep -Ein "[a-z]+form|form[a-z]+|[a-z]+form[a-z]+" alice.txt
``````

## Problem 4

Position yourself in /home/OMIS107/Lecture2. Print the lines of alice.txt where both “q” and “a” appear in the same word.

``````grep -Ein "q[a-z]*a|a[a-z]*q" alice.txt
``````

Extra Problem in class

Position yourself in /home/OMIS107/Lecture2. Replace all words where both “q” and “a” appear with -----.

Solution

``````sed -r "s/[a-z]*q[a-z]*a[a-z]*|[a-z]*a[a-z]*q[a-z]*/-----/g" alice.txt
``````

AI悦创·编程一对一

AI悦创·推出辅导班啦，包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」，全部都是一对一教学：一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然，还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线，随时响应！微信：Jiabcdefh

C++ 信息奥赛题解，长期更新！长期招收一对一中小学信息奥赛集训，莆田、厦门地区有机会线下上门，其他地区线上。微信：Jiabcdefh

• 0
• 0
• 0
• 0
• 0
• 0

• 按正序
• 按倒序
• 按热度