Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I am a bit confused regarding the usage of pipe | in python. I need a in depth explanation of its significance. Users please enlighten me regarding this.
Suppose I issued a command, ps aux | grep python then it shows the python processes running on the machine. I do understand it, but I need a analysed and in detail knowledge. Please help me out.
First, it's not Python you're talking about when you run ps aux | grep python, it's unix, usually within a bash shell. Second, the pipe operator means that you're taking the output of the first function and inputting it into the 2nd function.
In this case, you're taking the result of your process list from ps aux and finding anything to do with python from it using grep python. The grep command means that you're searching for the string "python" within the process list outputted by ps.
That command you listed is a shell command, not anything to do with Python specifically. You are saying:
"run the command ps aux and, instead of showing me the result, provide the result as input to grep python". Or, in other words, "pipe the output of the first command into the input of the second command".
grep accepts input and displays as output all of the lines of the input that contain the argument following grep. So grep python shows all lines in ps aux that contain the word python.
Python here is not being invoked in any way -- you're just filtering for that literal string, python, in ps aux.
| works as and of the two statement ps aux and grep python
So when you type ps aux | grep python it will return the common results of the two statement.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I used this command line to see what is inside grep command but it gives unlimited space to write. Why is this happening grep file.txt
It is finding instances of the literal text file.txt from standard input, aka your keyboard input.
If you want to search a file, use grep PATTERN -f FILE
Check out the grep man page for more details.
Plus, the entire point of grep is to search for a pattern, so you'll need that too.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
(EDIT)
I am creating a bash program that has many fully featured options as a networking program written in python. In my program, I am using the below command and it's specific output will be used as a variable.
I am looking for a command or method to display only specific terminal output of a command. For example if, in my script, I use the command:
iwconfig wlan0
Yet all I wish to see from this command is what mode in which wlan0 is set. (i.e. Master, Managed, Monitor, etc.)
I have looked and searched all over Google and Bash specific sites and cannot find a solution. I may be overlooking something.
The grep option you're looking for is -o, or --only-matching in its long form. It outputs only text that matches the search you gave it, and nothing else. For example:
iwconfig wlan0 | grep -o 'Mode:[^ ]*'
outputs Mode:Managed on my machine. The single quotes are necessary so that the shell won't try to interpret the [, ] and * characters (with double quotes, if you happened to have a file with precisely the wrong name in your current directory, the shell might wrongly expand your parameter to the name of that file). The regular expression inside the single quotes means "the text Mode:, followed by any number of non-space characters", which is exactly what you were looking for.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Is there any command that I could use to check the memory usage for a single linux command? For instance I have a script file (test.sh) which will read and extract word from a 100mb text file. How could I know how much memory does this command (./test.sh input_file.txt) would take?
Thanks for the advises there!!
Use the free command to check the usage of RAM.
To check the size of the program in memory you can check the /proc/[pid]/statm file. For details of the format of this file read man proc
Fetch the PID of the script from the script using the $$ variable (in bash).
EDIT
Other solutions:
ps u $PID | tail -n1 | tr -s ' ' | cut -d ' ' -f 5,6 Gives you the VMZ and RSS of the process with $PID.
Or may want to like to see only the process memory using
watch -n0.5 ps u $PID
this will update the usage of the memory for your process every 0.5 secs. Adjust the value for updating as required.
You can just use top to see that. When you execute your script, a shell process such as bash, will be create to execute the script for you. So, find the shell process in top and you can see how many memory it uses.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Normally in a Linux command you can specify another one to be run at the same time like this:
ls | grep "sys"
for example. In my case I have this command:
urlsnarf -i wlan0
and I can edit it like this to show filtered output:
urlsnarf -i wlan0 | cut -d\" -f4
but I also want to save the output to file and at the same time print text in the console so I edit it like this:
urlsnarf -i wlan0 | cut -d\" -f4 | tee output
but there is neither an output file nor printed output. Is there any way to fix this?
I imagine what's happening here is the pipe is being buffered. I haven't seen urlsnarf before, but it looks like it's a continuous monitoring process. According to the following post, you can't easily stop the pipe from being fully buffered:
How to make output of any shell command unbuffered?
The article linked from an answer there is a good read: buffering in standard streams
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Sorry for posting it here, but Google does a very bad job when searching for symbols.
What does the "|" mean in:
"some string" | someexecutable.py
It is the pipe symbol. It separates two programs on a command line (see Pipelines in the bash manual), and the standard output of the first program (on the LHS of the pipe) is connected to the standard input of the second program (on the RHS of the pipe).
For example:
who | wc -l
gives you a count of the number of people or sessions connected to your computer (plus one for the header line from who). To discount the header line:
who | sed 1d | wc -l
The input to sed comes from who, and the output of sed goes to wc.
The underlying system call is pipe(2) used in conjunction with fork(), dup2() and the exec*() system calls.
It's called pipe. It gives the stdout of the first command ("some string") as the stdin to the second command (someexecutable.py).
| is a pipe. It sends output of one command as input of the next. It is explained here http://www.ibm.com/developerworks/linux/library/l-lpic1-v3-103-4/#3-pipes