Hot answers tagged

2

This is the command that you need: ps aux|grep -P "Rl.*a\.out"|grep -oP "\d+"|head -n 1 | xargs lsof -p The key here is xargs. Commands such as grep and awk can accept the standard input (STDIN) as a parameter, or argument by using a pipe. However, others such as cp, echo and lsof disregard the standard input stream and rely solely on the arguments found ...


2

This is easier and only uses grep: grep -B1 PATTERN debug.log | grep -v 'PATTERN\|--' or, grep -B1 PATTERN debug.log | grep -v -e 'PATTERN' -e '--'


1

Bash use $ ls | grep root Cmd use > dir /b | findstr root where /b stands for bare list of directories and files


1

You can use Vim in Ex mode: ex -sc '1d2000|x' file 1 move to first line 2000 select 2000 lines d delete x save and close


1

You can use Vim in Ex mode: for k in *.txt do ex -sc '1s/tag1/tagOne/3|x' "$k" done 1 move to first line 3 select 3 lines s substitute x save and close


1

I would recommend using xargs when a command returns multiple lines (or records). In this case, the command returns a single PID and a shell feature known as command substitution would be an appropriate solution. This allows the output of one command to be used by another and is accomplished by wrapping the command that provides the input in $( and ). In ...


1

Your 1st complex command to find the PID based on name can be replaced by pgrep, e.g. $ pgrep -nf a.out 70512 Then to get the path from lsof, you can use conditional print in awk. So the command could be: $ lsof -p $(pgrep -nf a.out) | awk '$4 == "cwd" {print $9}' Above is based on the following lsof output: $ lsof -p $(pgrep -nf a.out) COMMAND ...


1

If you are looking for the occurrence of 3 consecutive "T" characters in a file, you can do that with grep. What did you try that didn't work? And, if you only want to check the first 2,000 lines of the file, you could pipe the output of the head command into grep. E.g., head -n 2000 somefile.txt | grep "TTT" If you want a count of the lines in the file ...



Only top voted, non community-wiki answers of a minimum length are eligible