CIS 18B ASSIGNMENT 2

grep & sed


Use grep -G grep -E or grep -F for the first three problems.

Save the results in an output file.


Use the following test data when you execute your commands to produce the result you turn in. However, do not assume this is all the data that your commands must process. Assume that other data must also be processed correctly.


Input file


*

*one *two *three

* a * b * c * d *

one * here

two * are * here

***hello***

goodbye*

*so long

*********

good morning

* note ***



1. Print all lines that contain an asterisk, and contain a character that is not an asterisk.


2. Print all lines that contain less than three asterisks.


3. Print all lines that have an equal number of asterisks at the beginning of the line and the end of the line. The character following the asterisks at the beginning of the line must be a character that is not an asterisk. The character preceding the asterisks at the end of the line must be a character that is not an asterisk.

4. Use a sed command to create an output file from the input file. The input file contains a block of text whose first line starts with a "#" and whose last line ends with a "\". Within this block only, turn the third "=" on each line into ">". You must use a sed command. The input file is called lab2_4_in. The output file is called lab2_4_out.


lab2_4_in

HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH#H

S++=+++=+++=+++=++=++=++=++=++=++=+

#+++=+++=+++=+++=++=++=++=++=++=++=

B++=+++=+++=+++=++=++=++=++=++=++=+

C++++=+++=?????????????????????????

D??????=+++=+++=++=++=++=++=++=++=+

+++=+++=+++=+++=++=++=++=++=++=++=\

J++=+++=+++=+++=++=++=++=++=++=++=+

TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\

TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT




5. Use a sed command to create an output file from the input file where each group of three lines from the input file result in two lines in the output file. From each set of three original lines, the first two lines are concatenated and the third is output as it is. You must use a sed command. The input file is called lab2_5_in. The output file is called lab2_5_out.



lab2_5_in

HHHHHHHHHHHHHHHHHHHHH

HHHHHHHHHHHHHHHHHHHHH

TTTTTTTTTTTTTTTTTTTTT

NNNNNNNNNNNNNNNNNNNNN

NNNNNNNNNNNNNNNNNNNNN

MMMMMMMMMMMMMMMMMMMMM

PPPPPPPPPPPPPPPPPPPPP

PPPPPPPPPPPPPPPPPPPPP

QQQQQQQQQQQQQQQQQQQQQ



6. Use a sed command to create an output file from the input file. The input file is formatted such that every field of every line is delimited from the next field with a "#". The command shoule swap the second and the third field of every line. You must use a sed command. The input file is called lab2_6_in. The output file is called lab2_6_out.


lab2_6_in

AAA#BBB#CCC#DDDD

GGG#HHHHHHHHHHHH

II#JJJ#KKKKKKKKK

LLLLLLLLLLLLLLLL

MMMM#MMMMMMMMMMM




7. Use a sed command to create an output file from the input file. The command will add the following two lines:


hello

De Anza Students

before every line of the input file which starts with a digit. You must use a sed command. The input file is called lab2_7_in. The output file is called lab2_7_out.


lab2_7_in

AAAAAAAAAAAAAAAA

2346HHHHHHHHHHHH

HHHHHHHH23499999

2KKKKKKKKKKKKKKK

9MMMMMMMMMMMMMMM