Question:
UNIX Command help!?
anonymous
2008-02-21 18:31:02 UTC
I've been having a hell of a time with these questions that are due tomorrow morning. These are the four questions I've been having problems with. If any of you are experts, I'm guessing they will be very easy questions, this is an intro UNIX class. Thanks in advance for any help fellas!

1. Give a command or sequence of commands that displays only the real name of a user. For example, for user mtaylor the command would display:

Matthew E. Taylor

2. Give a command or sequence of commands that uses the locate database to display a list of
probable locations of the Java compiler, javac. “Probable” locations are those that refer to a
file named javac, such as:

/lusr/share/software/java2/1.4.1/x86-linux/bin/javac
/lusr/share/software/java5/jdk1.5.0/solaris/bin/javac

whereas unacceptable locations would be:

/lusr/share/vim/vim60/syntax/javacc.vim
/lusr/share/software/java2/1.4.2/docs/tooldocs/solaris/javac.html
/lusr/share/software/studio4/sparc-solaris/modules/ext/javac.jar
Four answers:
anonymous
2008-02-21 20:25:19 UTC
1) the finger command will display information from the /etc/password file including the name field. Assuming the sysadmin put in the the information something like this might work for the user scooter:

finger scooter|grep Name|sed 's/.*://'



Finger might be implemented differently; I run FreeBSD and the output might be different under Linux or SunOS.



2) The locate command gives you a list of filenames, but the trick is determining which are commands. Use ls, with the -F option, to make picking them off easy:



locate javac|xargs ls -F|grep "[*]"|sed 's/\*//'



3) Use comm, but it requires files to be sorted, so sort first:



sort file1 >/tmp/file1.s

sort file2 >/tmp/file2.s

comm -3 /tmp/file1.s /tmp/file2.s

rm /tmp/file1.s /tmp/file2.s



4a) grep "ff" example1 example2

cat example1 example2 | awk '/ff/ {print}'



b) grep "[0-9]" example1 example2



c) grep "[B-Z]" example1 example2|grep -v "A"



If I come up with a third one for 4a I will edit the answer, but wanted to get this much to you before your midnight deadine.





===== edit =====

Third example for 4a; I was trying to make it more complicated than it needed:



cat example1 example2 | sed '/ff/p; d'



Prints all lines with ff, and deletes all others.
Rick B
2008-02-22 04:35:09 UTC
Looks like the theme is regular expressions/pattern matching.



1. Use 'finger' to get more info than you need and 'sed' to filter it (I think the real name follows 'Name: ')



2. Most likely grep to id lines with 'java*'? Allow the 2nd unacceptable location appears on the probable list



3. How about 'sort' the files to two temporaries and use 'comm' to find common lines?



4. a) 'grep', 'sed', 'awk' can all use pattern matching to find 'ff''s

b,c) 'grep' with appropriate pattern matching



===== edit as well ======

or do what ted says.
anonymous
2008-02-22 03:04:48 UTC
You can probably find the answers to ALL the questions in your text or reference book.
chainofcommand02
2008-02-22 02:36:33 UTC
#3, would that be the "diff" command?

#1, that isn't "whois," is it?



Sorry, my *nix is a little bit rusty...

Hope this helps!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...