a few single line command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting a few single line command
# 1  
Old 05-13-2011
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!
# 2  
Old 05-13-2011
show us what you think/have tried, and I'm sure you'll get some pointers...I know you say this isn't homework, but it sure smells like homework :-).
# 3  
Old 05-13-2011
for b i just made the sed command as

sed -n 's_.*".*\('"'.*'"'\).*".*_\1_gp'

for tcsh script question a i can do egrep '\w-\w+-\w' but output doesn t look same i know i must use smth like sed '//{N}'... but i have no idea how i need to continue

if u have an answer plz reply or don t test me whether it s hw or not
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

2. Shell Programming and Scripting

Su and run single line command

myenv.sh script sets LOG_DIR variable. I can run the script and echo the variable in a single line as: # First set LOG_DIR to some dummy 'NONE' value $ export LOG_DIR="NONE" $ echo ${LOG_DIR} NONE $ cat /tmp/bin/myenv.sh export LOG_DIR="/tmp/log" #The below command doesn't show the... (2 Replies)
Discussion started by: ysrini
2 Replies

3. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Shell Programming and Scripting

Running Two scripts in a single command line

Hi All, I have two scripts which i want to run in a single command line(or in a single script). And if both the scripts in the main script fail then i want to pass a value to a Application specific utility which will trigger some alert.The value can be anything. Somebody please help.It is... (1 Reply)
Discussion started by: shroh
1 Replies

5. UNIX for Advanced & Expert Users

Issuing a Here Document as a Single Line Command

How can I run a here document on just one line? I ask, because I need to issue it from C++ as a system() or similar command and for security reasons I don't want to write out a shell script file from the program and run it. For example, how could I write: passwd test <<EOF n3wp3ss... (3 Replies)
Discussion started by: BrandonShw
3 Replies

6. UNIX for Advanced & Expert Users

Merging two command into single line

1. du -sch int* | grep "total" | awk '{print $1}' first command result is 17K 2. echo "B" Result B i want the output is 17KB (2 Replies)
Discussion started by: kingganesh04
2 Replies

7. AIX

ls command output in single line

Hi, Can anyone suggest me how can I display the output of ls command in single line with some delimiter say pipe (|)? I know it can be done by writing a script by using the loops but I wanted to know are there any other single line commands? Thanks for your help Sheshadri (7 Replies)
Discussion started by: arsheshadri
7 Replies

8. Shell Programming and Scripting

Single line file editing command?

Hello everyone. I have been reading a lot about the various different text editors at my disposal through Unix, but I just can't seem to close the deal for what I am trying to do. Is there a way to issue a single line command to edit a file where pattern=x, and do it non-destructively AND in-place?... (1 Reply)
Discussion started by: gator76
1 Replies

9. UNIX for Dummies Questions & Answers

run command Unix on a single line

Hi everybody.. I need to enter in bash mode and then run a command and this just in a single command line. I tried : "bash ^M| somecommand" but nothing.. How do I do to simulate the return button just right after the bash command ? Thanks.. (8 Replies)
Discussion started by: Riddick61
8 Replies

10. Shell Programming and Scripting

single line command

i need to search for a single pattern in three different logs....what would be the best one line script???? (4 Replies)
Discussion started by: roshanjain2
4 Replies
Login or Register to Ask a Question