need help

need help

Post by Yaro » Wed, 08 Jan 1997 04:00:00



Can you help me solve some problems in unix shell??

I need to write list of commands sepirated by pipes to solve this questions:

1: By list of commands show on screen the file-list in the corent directory
that their names are made only by letters [a-z][A-Z] and by underline [_]
2: Show the line numbers and the lines from a file (i.e. hello) that contains
the string "***hello***"
3: Show the lines in a file (i.e. less_then_five) that contains less then five
letters.
4: Show all the lines in a file that contains "ilegal" words - words that have
capital letters in the middle of a word (assuming that the file contains
letters only).
5: A list of commands that used as a "filter" to a file - a filter that
deletes all blank rows (blank row is also a row that uses only spaces and\or
tabs)
6: Show a list of files that are in directory a and in directory b (files with
the same name in both directorys)
7: Like the last one but files that are in a but not in b
8: Asuming that the string Hello is showed more than once in some files -
write the command listing that shows the file with the largest number of rows
that contain this string (i.e. the files hello1,hello2,hello3)  

 
 
 

need help

Post by Kurt J Lan » Wed, 08 Jan 1997 04:00:00


Looks like a homework problem set to me. Now how are you
supposed to learn anything if someone tells you the
answers?

Quote:>Can you help me solve some problems in unix shell??
>I need to write list of commands sepirated by pipes to solve this questions:
>1: By list of commands show on screen the file-list in the corent directory
>that their names are made only by letters [a-z][A-Z] and by underline [_]
>2: Show the line numbers and the lines from a file (i.e. hello) that contains
>the string "***hello***"
>3: Show the lines in a file (i.e. less_then_five) that contains less then five
>letters.
>4: Show all the lines in a file that contains "ilegal" words - words that have
>capital letters in the middle of a word (assuming that the file contains
>letters only).
>5: A list of commands that used as a "filter" to a file - a filter that
>deletes all blank rows (blank row is also a row that uses only spaces and\or
>tabs)
>6: Show a list of files that are in directory a and in directory b (files with
>the same name in both directorys)
>7: Like the last one but files that are in a but not in b
>8: Asuming that the string Hello is showed more than once in some files -
>write the command listing that shows the file with the largest number of rows
>that contain this string (i.e. the files hello1,hello2,hello3)  

--
--


 
 
 

need help

Post by Icarus Spar » Wed, 08 Jan 1997 04:00:00



>Can you help me solve some problems in unix shell??

Probably.

Quote:>I need to write list of commands sepirated by pipes to solve this questions:

>1: By list of commands show on screen the file-list in the corent directory
>that their names are made only by letters [a-z][A-Z] and by underline [_]

ls | grep -v '[^a-zA-Z_]'

Quote:>2: Show the line numbers and the lines from a file (i.e. hello) that contains
>the string "***hello***"

grep -n '\*\*\*hello\*\*\*' hello

Quote:>3: Show the lines in a file (i.e. less_then_five) that contains less then five
>letters.

grep -v '^......' less_than_file

Quote:>4: Show all the lines in a file that contains "ilegal" words - words that have
>capital letters in the middle of a word (assuming that the file contains
>letters only).

grep '[a-z][A-Z]' filename

Quote:>5: A list of commands that used as a "filter" to a file - a filter that
>deletes all blank rows (blank row is also a row that uses only spaces and\or
>tabs)

grep -v '^[     ]*$'
where there is a space and a tab between the brackets.

Quote:>6: Show a list of files that are in directory a and in directory b (files with
>the same name in both directorys)

dircmp a b
(if you have dircmp), otherwise
( ls a  ; ls b ) | sort | uniq -c | sed -n 's/ *2 *//p'
or
f=`ls a`;cd b;ls $f 2>/dev/null
or, if your shell is up to it
comm -12 <(ls a) <(ls b)

Quote:>7: Like the last one but files that are in a but not in b

dircmp a b
comm -23 <(ls a) <(ls b)

Quote:>8: Asuming that the string Hello is showed more than once in some files -
>write the command listing that shows the file with the largest number of rows
>that contain this string (i.e. the files hello1,hello2,hello3)  

grep -c Hello hello1 hello2 hello3 | sort -rn | head -1

Why do I feel I am doing someones homework?
Icarus

 
 
 

need help

Post by Stefan `Sec` Ze » Thu, 09 Jan 1997 04:00:00




> >Can you help me solve some problems in unix shell??

> Probably.
[...]
> Why do I feel I am doing someones homework?
> Icarus

Because you are doing someones homework ? :)

BTW.: didn't know ``comm'' till now, so i also learned something :)

CU,
        Sec
--
Fuer die Raupe ist es das Ende der Welt,
Fuer den Rest der Welt ist es ein Schmetterling
                " mit ISDN kann man im Internet schneller warten "