Tag Info

Hot answers tagged

9

tl;dr You don't need a quantifier, just grep for PROC: ls | grep PROC long version The asterisk in your ls line, is not the same as the one in your grep line. When you have an unescaped asterisk on the command line, the shell will expand it before ls sees it, this is called globbing. An asterisk alone expands to all files in the current directory, try ...


2

echo $var | grep -e "Some" is actually the right approach. When piping the output through grep with |, it no longer appears on the console. From the man page of Bash: Pipelines A pipeline is a sequence of one or more commands separated by one of the control operators | or |&. The format for a pipeline is: [time [-p]] [ ! ] command [ ...


2

bash now allows here strings, eg: var="Some random string" grep -e "Some" <<<"$var"


1

Tried this on my sh-compatible terminal: $ grep --only-matching --perl-regexp "[^.]*searchterm[^.]*" \ <<< "Foo blah. Blah blah searchterm blah blah. Foo bar." Blah blah searchterm blah blah $ Can be abbreviated to grep -oP. I think the problem with the regex you provided is specifying .*to how greedy you wanted it to be (as stated by ...


1

You are missing a space in your cut command. cut -d\ -f1 should be cut -d\ -f1 since you are using \ to escape the following space (using space as the delimiter), and arguments are separated by a space, there is a missing space between the -d and -f (for cut it looks like you are trying to use " -f1" as a delimiter, which is more than one character). ...


1

Forget using grep or awk and do it in your shell. while IFS= read -r line do echo "$line" > "$line" done < FILE


1

Are you determined to use Grep/Awk? There is a much easier way to do this: while read f; do echo "$f" > "$f"; done<file.txt Make sure to use quotes, especially for the file name.


1

By default, read will only read only one line at a time. For example, here we provide three lines of input and, as you can see, read only reads the first line: $ IFS=$'\n' read -ra displays <<< $'a\nb\nc\n'; declare -p displays declare -a displays='([0]="a")' The -d option can be used to change this behavior. For example: $ IFS=$'\n' read -d ...


1

One way is to create a list of files containing one keyword, then search this list for the second, as in: grep -l word2 $(grep -rl word1 .) If you want to show the matches, add a third grep, as in: grep -E 'word1|word2' `grep -l word2 $(grep -rl word1 .)` It is also possible to use sed to perform grep functions, and it may be possible to do what you ...


1

You could always using MinGW and MSys (or MSYS2) on Windows to do what you specified in the question, which come with find, grep and many other commonly used Unix commands.


1

If you have a limited version of ps such as is found in busybox, you can get the process start time by looking at the timestamp of /proc/<PID>. For example, if the pid you want to look at is 55... # ls -al /proc | grep 55 dr-xr-xr-x 7 root root 0 May 21 05:53 55 ... and then compare it with the current date... # date Thu May 22 ...



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