LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Having problems figuring out these commands (https://www.linuxquestions.org/questions/linux-newbie-8/having-problems-figuring-out-these-commands-171874/)

Dandy 04-18-2004 09:59 PM

Having problems figuring out these commands
 
1. Can you please give me an example of a command that would display a text file named myfile.txt and sort it on the same command line using the pipe command to join the two parts together.

(This is a Scenerio)
2. I have a log file named logins.txt that monitors logins to my system. It contains multiple lines with duplicate user names. What command could I use so that I could display the file showing only one instance of every login?

3. If I have a script named, myscript.sh, what is the syntax for running it at the command prompt?

4. What command would I use to give me the last 20 lines of a file called inventory.txt?
:)

MiscGeek 04-18-2004 10:17 PM

Re: Having problems figuring out these commands
 
Quote:

Originally posted by Dandy

3. If I have a script named, myscript.sh, what is the syntax for running it at the command prompt?

If you have the correct header for the file ( #!/bin/sh ), and it's executable, chmod +x myscrip.sh, you can simply type the file name to run it. Note: if you're in the same directory you have to type ./myscript.sh.

Another option is to call like so /bin/sh myscript.sh
Quote:


4. What command would I use to give me the last 20 lines of a file called inventory.txt?
:)

tail -n20 inventory.txt

bigrigdriver 04-18-2004 10:21 PM

1. cat myfile.txt | sort --dictionary-order
2. cat logins.txt | sort --unique
3. If you CD to the directory which contains myscript.sh, then ./myscript.sh will execute the script, assuming execute permissions are set. The ./ tells Bash that the script is located in the current working directory. Otherwise, from anywhere, /path/to/myscript.sh will work also work.
4. tail -n 20 inventory.txt


All times are GMT -5. The time now is 05:58 AM.