grep

awk inside function causing errors

awk inside function causing errors I’m trying to add the following to my .bashrc: cpu_info() { top -b -n1 | grep Cpu(s) | awk ‘{print $2 + $4}’ } but bash is telling me: bash: .bashrc: line 131: syntax error near unexpected token `(‘ bash: .bashrc: line 131: ` top -b -n1 | grep Cpu(s) …

Total answers: 1

How to use grep string that has double quotes in it

How to use grep string that has double quotes in it So I’m running a simple alias called vpn which runs a command and has an output, which I put into a .txt file. If interested to what exactly then here is the alias alias vpn="docker exec -it qbittorrent curl -sS https://ipinfo.io/json > $HOME/vpnstatus.txt" and …

Total answers: 1

How can I use find paired with grep to delete files

How can I use find paired with grep to delete files I am attempting to write a script to delete files from a directory. find /home/docs/* -name "*.log" -type f -print -exec rm -f {} ; The above works however I need to use grep to target directories using grep. When I put grep I …

Total answers: 3

Recursively search for txt files that has all the search strings

Recursively search for txt files that has all the search strings I want to find all the files that has the words “Who”, “What”, “Why”, “How”, “When”. All of the words, in any order. Case Insensitive I tried: grep -rl –include=’*.adoc’ "Who" . | xargs grep -l "What" | xargs grep -l "Why" | xargs …

Total answers: 2

multiline grep search into separate files per occurence

multiline grep search into separate files per occurence I have a file as following: example.txt -1 15 1 0 0 11 -1.0000E+001 1.0000E+001 -1.0000E+001 2 0 0 11 1.0000E+001 1.0000E+001 -1.0000E+001 … 29 0 0 11 1.0000E+001 2.0000E+001 1.0000E+001 30 0 0 11 5.0000E+000 5.0000E+000 5.0000E+000 -1 #ffafsda -1 780 1 116 1 2 1 …

Total answers: 5

changing grep command –color from red to another color

changing grep command –color from red to another color I’m searching from the file using grep command with particular pattern, sysadmin@localhost:~$ grep bash /etc/passwd which return the output like below root:x:0:0:root:/root:/bin/bash operator:x:1000:37::/root:/bin/bash sysadmin:x:1001:1001:System Administrator,,,,:/home/sysadmin:/bin/bash How can I change the default color of red to something different (eg.blue) Asked By: SpiderMan || Source The simple solution: …

Total answers: 1

caret character unexpected behaviour in regular expressions with grep

caret character unexpected behaviour in regular expressions with grep i was running grep commands from "William Shotts" regular expressions example.It seems,the caret character is not doing what it is supposed to do. I have four test files with all the bin entries in text form.My intention is to find the keywords starting with "zip" from …

Total answers: 1

Is it possible to grep this output from gpg

Is it possible to grep this output from gpg Take the following command (real example) : ~$ gpg –edit-key foo@bar.net showpref quit (…) [ultimate] (1). Foo Bar <foo@bar.net> Cipher: AES256, AES192, AES, CAST5, 3DES AEAD: Digest: SHA256, SHA1, SHA384, SHA512, SHA224 Compression: ZLIB, BZIP2, ZIP, Uncompressed Features: MDC, AEAD, Keyserver no-modify Preferred keyserver: ldap://keyserver.pgp.com ~$ …

Total answers: 1

How to add content to a file before the last } character using Busybox utilities?

How to add content to a file before the last } character using Busybox utilities? There is a file with contents { "first_name": "John", "last_name": "Smith", "is_alive": true, "age": 27, "address": { "street_address": "21 2nd Street", "city": "New York", "state": "NY", "postal_code": "10021-3100" }, "phone_numbers": [ { "type": "home", "number": "212 555-1234" }, { "type": …

Total answers: 5

GREP error: warning: cannot select font 'i'

GREP error: warning: cannot select font 'i' I am in the process of learning the usage of iscsiadm and somehow I noticed a strange behavior of grep. Attempting to run the following grep command man iscsiadm | grep "aia" results in troff:<standard input>:498: warning: cannot select font ‘i’. I played around and found out that …

Total answers: 1

Find all the folders that are concealed using 'chflags'

Find all the folders that are concealed using 'chflags' I have concealed some folders on my laptop using chflags: chflags hidden hide-me And I don’t remember where exaclty these folders are located. How is it possible to find all of them? (Probably by using find and/or grep.) Asked By: jsx97 || Source Something like that: …

Total answers: 1

Why doesn't the given command mask other lines?

Why doesn't the given command mask other lines? Command: sudo find / -name miniedit.py -print | grep -i "miniedit" | tail -1 Output: find: ‘/proc/10031/task/10031/net’: Invalid argument find: ‘/proc/10031/net’: Invalid argument find: ‘/run/user/1000/gvfs’: Permission denied find: ‘/run/user/1000/doc’: Permission denied /usr/share/doc/mininet/examples/miniedit.py Expected output: /usr/share/doc/mininet/examples/miniedit.py What am I doing wrong? Asked By: kesarling He-Him || Source You …

Total answers: 1

Why does grep ignore the leading '.'?

Why does grep ignore the leading '.'? I am trying to find a string in a web page downloaded w/ curl. I am using grep to find the string matching a regular expression pattern. Following is the string I am trying to find: ./download/file.php?id=86753 This string is part of this larger string in the webpage: …

Total answers: 4

How to use a variable in a command inside of a bash file

How to use a variable in a command inside of a bash file I use this command directly on our redhat linux server 8.8 and it’s working correctly and I get the result I want: grep ’01-FEB-2024′ /u01/app/server1/listener_scan/trace/listener_scan.log | awk ‘{ if ( $NF != 0 ) print $0 }’ I need to automotize this …

Total answers: 3

As soon as I touch a new file, my ls command with grep stops working

As soon as I touch a new file, my ls command with grep stops working I’m trying to find all the files in my home directory with a specific extension. If I only have one instance of the file extension, the ls command works perfectly fine, but as soon as I touch a new file …

Total answers: 1

GREP matching 6-7 digits within other data

GREP matching 6-7 digits within other data I am trying to create a Regular Expression that will match a string of digits that is 6 or 7 digits long. [0-9]{6,7} This works but i dont want a match in strings that are longer than 7 digits. Please see the sample data below with the digits …

Total answers: 6