Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
25 views

Dealing with whitespaces in file names after git grep -l

I'm trying to run the script below and I'm struggling with pathspec error when the filename has whitespaces. I have already read some other posts around here, but since I am not an expert I was not ...
O Pardal's user avatar
  • 103
0 votes
0 answers
27 views

Grep’s result coloring, and right-to-left scripts

I have a text file with a single line that contains the single Yiddish word azoy, in Hebrew script: אַזױ. Then I grep for occurrences of the oy character, ױ. (This is highly simplified of course, in ...
Ruud Harmsen's user avatar
1 vote
0 answers
21 views

How to calculate GUI used memory widget value?

OS: Kubuntu 22.04.4 LTS x86_64 to display above: neofetch --stdout |grep 'OS:' GUI = Graphical User Interface GUI used memory = see widget image below. . 2nd method to display used memeory = 2211 MB =...
joseph22's user avatar
  • 367
0 votes
1 answer
46 views

no-ignore-case in grep command

In man page of grep --no-ignore-case matching control has the following description: Do not ignore case distinctions in patterns and input data. This is the default. This option is useful for ...
tahzibi.jafar's user avatar
1 vote
0 answers
57 views

How to command pv (Pipe Viewer) to work with diff?

using: OS: Kubuntu 22.04.3 LTS x86_64 diff (GNU diffutils) 3.8 Copyright (C) 2021 Free Software Foundation, Inc. pv 1.8.0 Copyright 2023 Andrew Wood, pv = Pipe Viewer commands to display above: ...
joseph22's user avatar
  • 367
2 votes
1 answer
297 views

How to Print, when columns have spaces - awk?

Problem: desired columns have text with spaces SAMSUNG MZNLN128HCGR-000H1 undesired columns have text with spaces, see VENDOR = M.2 SSD awk only printing the first word. awk not printing the column ...
joseph22's user avatar
  • 367
3 votes
1 answer
117 views

Why can I ssh and return a result faster than Linux can with a bundled command?

I'm writing a short bash script that involves logging into roughly 100 nodes and counting the number of processes running in top with my username, and I'm trying to combine the ssh-related processes ...
Headphones's user avatar
1 vote
0 answers
207 views

How to use diff for files names, not file content, and echo "differences!"

Background: While comparing 2 directories, command1, from the internet: diff <(find "$DIR1" -printf '%P\n' | sort) <(find "$DIR2" -printf '%P\n' | sort) | grep '^[<>]' ...
joseph22's user avatar
  • 367
4 votes
2 answers
130 views

Why is `grep "^ *[^<]" <somefile.xml` giving unexpected results

Say I have a file containing some xml like so: <headtag> <firsttag>a string</firsttag> <secondtag>a string</secondtag> <subleveltag> a line with no tag &...
DryLabRebel's user avatar
-1 votes
1 answer
165 views

write a efficient for loop in bash for multiple files (.PDB files)

I have problem with this script: #!/bin/bash for filename in /home/hb/pg/ensemble/pdbs/P24941/raw_pdb/*.pdb; do grep COMPND $filename | grep "CHAIN:" -B 1 | sed 's/COMPND//g' | sed 's/...
shahed's user avatar
  • 9
0 votes
1 answer
2k views

Using grep to search for files with a specific extension [duplicate]

I'm trying to recursively look for C Sharp files containing specific text using a bash prompt on Windows Subsystem for Linux. If I type grep -l -i -r "public virtual List<" /mnt/c/mycode/*...
Eric's user avatar
  • 1,273
4 votes
3 answers
2k views

How to check if a command is running currently? [duplicate]

I want to check if a command is running with the following if clause, but it's always true, whether command actually is running or not: if [ $"(ps aux | grep curl)" ]; then echo is; else ...
Saeed's user avatar
  • 423
0 votes
2 answers
583 views

How to combine tee, sed and grep?

I have a command after which I place | tee >(sed $'s/\033[[][^A-Za-z]*[A-Za-z]//g' >> ~user/filepath/file.txt) The tee is redirected to sed $'s/\033[[][^A-Za-z]*[A-Za-z]//g' which removes the ...
qwerty's user avatar
  • 11
1 vote
1 answer
51 views

How do I correctly execute 'vim $(grep -rli pattern | sed 's/\(.*\)/"&"/')' in bash?

I am trying to edit files that contain text matching a regular expression with vim and use the following command in bash to do that: vim $(grep -rli pattern | sed 's/\(.*\)/"&"/') I ...
René Nyffenegger's user avatar
4 votes
3 answers
2k views

Copying a path in the terminal with the keyboard

I often find that when using the command line, I need to copy a path that appears in the output of the last command. For example I might use find . | grep like this: [user@localhost /tmp]$ find . | ...
Raffi's user avatar
  • 163
5 votes
1 answer
2k views

How to print and pipe log file at the same time?

I use this to check the log lines of a log file until the occurrence of a specific event (taken from this answer to Monitoring a file until a string is found): (tail -f -n 0 test.log &) | grep -q '...
not2savvy's user avatar
  • 588
0 votes
1 answer
1k views

How do I change the order in which grep looks for pattern in files by filename

I have a directory with a bunch of files with numerical filenames like this: 1 - filename 2 - filename 3 - filename etc... They don't have leading zeroes, so if I do something like grep -oha "...
Mihail's user avatar
  • 1
1 vote
1 answer
270 views

what is the difference between 'grep -n ' \.*' test.txt' and grep -n '\.*' test.txt

When I run grep -n ' \.*' test.txt , I get: 1:Hello! This is a Unix \ Linux test text file. 2:It is being used to check multiple grep commands. 3:It is very useful. 4:.Below are some tabular ...
Venus's user avatar
  • 11
0 votes
1 answer
431 views

Capture process output with sed, capture block of text and then filter inside it

There is some stdout that I would like to filter with sed but I don't know how. The stdout example would be: . . . Model a. # This should be captured . . . Metrics results: # This ...
eljiwo's user avatar
  • 103
0 votes
1 answer
783 views

Displaying users and their home directory but NOT WITH awk

I have seen similar questions and I actually found the solution using awk command, but I'm not allowed to use it in my homework. so I want to know if there is another way of displaying all the users ...
Saad Out03's user avatar
0 votes
2 answers
701 views

remove duplicated lines taking into account only two columns

I have a file that has some duplicated lines if I take into account only the two first columns. For example 2 2 7 7 1 1 3 3 1 1 4 4 1 1 5 5 1 1 6 6 3 3 7 7 4 4 9 9 4 4 2 2 In this example, I have ...
Eric González's user avatar
0 votes
0 answers
323 views

macOS terminal: show filename with colors when using grep

When using Ubuntu I get these colors when using grep (grep -r "MSP" .): I want the same result when using macOS Monterey. I tried to add export GREP_OPTIONS='--color=auto' to my bash ...
Miguel's user avatar
  • 101
0 votes
2 answers
495 views

How can I see the lines where matching patterns occur in grep for multiple patterns in multiple directories

Thanks for all the input and effort, I've been able to find a solution to my "problem". find . -type f -name '*.csv' -print0 | xargs -r0 grep -rn string1 | grep string2 | grep string3 ...
pRieS's user avatar
  • 1
0 votes
1 answer
286 views

Piping PCRE grep into sed

I wanna sed this file, but the BRE in sed is not working as well as I hope. What I have now is basically just : $ cat Dungeon | grep -P -o '<\/.*?>' My question is how do I sed this? I want to ...
TK Flagrante's user avatar
1 vote
1 answer
1k views

Keep Color output with grep at systemctl status

I'm trying to get the original color of the output of this command with grep: sudo systemctl status telegraf | grep -e ● -e Active Output of command with this command the output is red, but i want it ...
Tobias2001's user avatar
0 votes
2 answers
123 views

Find files in git that have entry in .editorconfig

I want to find all of the files in git that have some extensions. The list of extensions is generated from my .editorconfig file. Say I have a list of file extensions such as: .css .html .java .js (...
User1648374637563's user avatar
0 votes
3 answers
2k views

How to execute kill `ps -ef | grep 1.sh` command as SUDO SU from batch file through Putty terminal to kill ALL process, with given name not only 1st?

I try use this command: start "" putty.exe -ssh -load NameOfSessionInPutty -m "C:\Program Files\PuTTY\MYCOMMAND.txt" -t MYCOMMAND.txt contains: sudo su - -c "kill `ps -ef | ...
Kostia's user avatar
  • 15
0 votes
1 answer
2k views

Odd behavior with grep -q in a bash script

I'm trying to write a small bash script that will check if each element of a sequence of numbers is in a given file, and print the ones that aren't. find_missing.sh: #!/bin/bash for num in {1..5}; do ...
Nathan Pierson's user avatar
0 votes
1 answer
78 views

Weird grep behavior with CJK characters? (bash)

grep fails to match certain strings with CJK characters. For example. Create a text file with content below: ==ShellType.サモナ\u30FC== Use grep. >> grep "ShellType.サモナ\u30FC" ...
user2771324's user avatar
0 votes
2 answers
84 views

Grep Sed with bash

I'm trying to achieve the following using bash and sed where the file containing below strings qa2.test.m.xyz.com 554 1723 21 qa88.test.nj.xyz.com 1723 554 21 443 80 qa2.lite.xyz.com 554 1723 21 ...
m4xx's user avatar
  • 75
0 votes
1 answer
346 views

grep for lines in shell script, send to xargs with $1 set

I have a shell script (I use GNU bash 4.4.20 on Ubuntu 18.04) with a list of commands I often run, e.g.: sudo program1 $1 foo arg1 sudo program2 $1 foo arg2 sudo program1 $1 bar arg3 sudo program2 $1 ...
nonagon's user avatar
  • 583
1 vote
1 answer
6k views

Grep with option -P in busybox

I want to run a grep command with option -P in a BusyBox v1.31.1 () multi-call binary inside a kubernetes pod with the image curlimages/curl:7.75.0 curl -s -X GET "https://api.cloudflare.com/...
A.Dumas's user avatar
  • 273
1 vote
2 answers
5k views

Extract key from key-value pair

I have a file looking like that. mke_version = "3.3.7" msr_version = "2.8.5" mcr_version = "19.03.14" I want to print from file only key ...
Lotarc's user avatar
  • 33
1 vote
0 answers
143 views

bash grep not finding all instances of gene

I have a file1 which has gene names: Appl Bsg mt:CoI mt:CoII mt:CoIII I have file2 which has all matches of those gene names in the genome: "FBgn0000108"; "Appl"; "...
mikamatvat's user avatar
0 votes
1 answer
577 views

Find number of files that contain certain String

I have a directory containing a vast amount of xml files. I would now like to find the number of files (and optionally the names of said files) that contain a certain string. XML tags do not really ...
T A's user avatar
  • 103
1 vote
1 answer
69 views

Would you expect different outputs from these two command chains?

I'm working on a project for a Linux class, we're writing a script to pull stats from a log file. This specific command chain is to get the number of users running MSIE 6.0. I'm wondering why I'm ...
Theodore Robertson's user avatar
0 votes
1 answer
1k views

Grep with a variable in a script

I have this code that returns the number of files in a directory with the name wordpress.*.tar.gz This code works NUM_BACKUPS="$(ls -l ${POOL_PATH}/${BACKUP_PATH} | grep -c '\wordpress.*.tar.gz$')...
user1227713's user avatar
0 votes
0 answers
120 views

Filter whole line from output in command line

I'm trying to find a bottleneck caused by some MySQL query, which oftentimes overloads the web server. Then I found this useful command: mysqladmin -u myusername -p -i 1 processlist which every ...
luis.ap.uyen's user avatar
0 votes
1 answer
1k views

grep for same occurrence more than once

Is it possible to grep or awk for more than 1 occurrence of the same string from a file? awk '/$STRING|$STRING/' file grep -e $STRING -e $STRING file I tried other options but still not able to get ...
user1212006's user avatar
0 votes
0 answers
157 views

Select part of PATH variable in bash_profile and insert it into another file

Fairly new to anything Linux. I have a path variable in my users' bash profile that we'd like to utilize from some of our scripts on the server. The part of the script that I'm changing is as follows ...
Oxyauna's user avatar
1 vote
2 answers
647 views

recursive grep does not list matches from some files

I am using GNU grep 3.4 to find scripts that contain a certain pattern. For this, I call grep recursively like so grep -rin . -e "pattern" The pattern is just a word, no regular expression....
buddemat's user avatar
  • 162
1 vote
1 answer
641 views

AWK/SED/GREP - print M lines after the Nth occurrence of a match

I am looking to display M lines after the Nth occurrence of a match. Actually I need to do this in order to split a file containing Nth <regex> always followed by M lines into Nth different ...
Lowrenzo's user avatar
6 votes
1 answer
2k views

Inverse grep using a pattern file doesn't show non-matches

I have two nearly identical files, "foo" and "bar". Each file has thousands of lines, one number each line. If I sort and then diff both files, this is the result: $ diff foo bar ...
That Brazilian Guy's user avatar
0 votes
1 answer
655 views

'grep' command not highlighting User input word in the Search result

I am trying to write shell script as below to search user inputted word and highlight the word in the search result - User input: echo -n -e "What you wanna search:" read userinput Save the ...
Khondakar's user avatar
3 votes
2 answers
1k views

how do I write a line number divisible by 3 in bash from an input file?

Create a shell script which prints the line contents when the line number is divisible by 3 from an input file. Assume the first line is line 1. At the end of the script, if the total number of lines ...
jiji's user avatar
  • 31
0 votes
1 answer
390 views

grep AND OR operators combined with IP addresses

I'm trying to find a way of streamlining my grep searches and be more granualar. An example of what I want to achieve: a netstat output searching for a particular IP AND the word established OR ...
Kev's user avatar
  • 3
1 vote
1 answer
83 views

Display dirs tree based on a file content

$ find ./ | tac ./dir1/file -> "abc" ./dir1 ./dir2/file - > "abc" ./dir2 ./dir3/file -> "xyz" ./dir3/dir3_1/file - > "abc" ./dir3/dir3_1 ./dir3 or $ tree ├── dir1 │   └── file -> "...
roman-drozd-it's user avatar
0 votes
1 answer
635 views

Troubleshooting grep not returning whole lines during search?

I have two tab delimited txt files- FileA has 30,000 lines and 10 columns. FileB has 600 lines and 1 column. My goal is to search the 30,000 lines of FileA using the search terms in FileB and output ...
genome454's user avatar
0 votes
2 answers
418 views

Why is this grep skipped after wget?

I'm trying to grep a string from the HTML output from wget in order to concatenate a URL together. Using the suggestions here I tried wget -O - https://www.printable-puzzles.com/download.php?p=cw2&...
Bill's user avatar
  • 1
0 votes
1 answer
57 views

Grepping specific lines with the same pattern

I am currently writing a bash script to grep out certain lines as shown in bold. However when I do a grep 'number', all the irrelevant lines will appear as well. Is there a way to just grep out the ...
CurrySauce's user avatar

1
2 3 4 5 6