05-13-2011
10,
0
Join Date: Mar 2011
Last Activity: 13 May 2011, 1:49 PM EDT
Posts: 10
Thanks Given: 0
Thanked 0 Times in 0 Posts
a few single line command
i m trying to find the answers of a past year exam questions , i m sure it ll be very easy for u guys , this is not a hw assignment or somth. i just wanna be sure of right answers .
write a single instruction to perform each of the following tasks:
(u r allowed to use c shell, and u can use regex with other basic commands like (e)grep or sed but not awk) , point is it must be SINGLE INSTRUCTION
try to write any u can , here is the questions;
a-) To display all lines that end with the word stored in X, followed by a period. If the word stored in X is “happy”, for example, then lines like these would display:
They were happy.
We are happy.
b-)
To print quotations within quotations on one line. For example, the input lines:
Joe said, "I heard that Mike said, 'That is OK.' So I guess it is OK. "
"But I heard Mike say, 'No,'" I replied.
"This line has" 'NO' output.
"This line has" 'YES' "output."
Will yield the output:
'That is OK.'
'No,'
'YES'
Note: You may assume that the ' and " symbols are only used for quotations.
(So you won’t have phrases like this: 'That's OK,' which has 3 ' symbols.)
So, formally, here is what you are looking for: A region inside of " symbols which itself contains a region inside of ' symbols. If you find this, then you print the inner region, along with the ' symbols.
c-) In part b, the line:
"This line has" 'YES' "output."
Really should not have printed, because the YES is not inside of a pair of " symbols. So now extend the expression from part b, so that it excludes lines like this, by ensuring that the part inside of ' symbols comes after an odd number of " symbols.
d_) Identify all hyphenated words in a file. For example, if you have the following file:
% cat file
There are many hyphenated words
in this file.
This ultra-fast-hardening glue is
a good choice for water-resistant-
bonding applications. Our no-risk, money-
back guarantee is out-of-this-world.
Then the output of your pipe is:
ultra-fast-hardening
water-resistant-bonding
no-risk
money-back
out-of-this-world
Note: There are no punctuation symbols in the output, except for the hyphens.
Note: Hyphenated words can cross line boundaries.
**************************************************************************************************** *****
Write tcsh scripts for each of the parts below. The names of the scripts are parta, partb, partc,
a. Write a script to shift over any input flags and then print the remaining arguments
Here, a flag is identified by its first character being a “-”.
Here also, flags must come before the other arguments
b. Write script that first runs parta and captures the result. Using this result, it then checks to see if there are either two or three arguments remaining. If not, then an error message is printed and the script exits with a value that indicates an error.
If yes, then the script prints the arguments captured from the output of parta.
---------- Post updated at 10:24 AM ---------- Previous update was at 08:58 AM ----------
wooow 35 views no reply!