Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [grep]

grep is a command-line utility that is used for searching text.

5
votes
2answers
460 views

Given the result of grep -n, how can I open vim in that specific line? (using only keyboard)

When I run grep "keyword" -n and get the following list of results: a/b/c:10: keyword a/b/c:70: keyword a/b/d:50: keyword How can I open one of the files (say the 2nd in list) in the line ...
3
votes
2answers
113 views

how to compare list of functions from 2 files?

I wanted to list all functions in 2 files I have, so I used: cat <file_A> | grep -E "^function" cat <file_B> | grep -E "^function" How can I compare the outputs and highlight the ...
1
vote
1answer
44 views

How do I transfer certain parts of the file to another file?

I have a FILE1 NAMES START Hi, How are you? Good to see you start Aaron Kyle Robert stop Official use only Stamps here start Riley Gayle stop Bicycles here United Pawns start Alex Ford Sergio ...
2
votes
2answers
507 views

How do I read line by line in a file using while loop, and in each iteration, grep each line to compare to a string?

I have a file called abc.txt with the contents as follows: 1: It is a shell script 2: There are few lines in this file 3: I am good with programming in C, but beginner in shell 4: We are going ...
0
votes
4answers
60 views

Is it possible to use grep command nested?

I mean, when I run dpkg -s thunar | grep "Depends" it displays all dependencies for thunar file manager. How to run, for example dpkg -s thunar | grep "Depends" | grep "gtk" to display only ...
0
votes
1answer
41 views

How to grep multiple files with start of same file name + date range

Hi trying to figure out how to grep to list and output multiple file name + date range. Example file name "TW_CAMPAIGN_OB_20180801", would like to search date range from Aug 2018 - Nov 2018. Please ...
0
votes
1answer
57 views

Why isn't grep working with iostat?

I'm trying to collect some disk usage statistics as specified here, for using with this nagios plugin In short it should get the tps for the second lecture in the output comming from iostat like ...
0
votes
2answers
35 views

After a particular grep match, I want to transfer all the following contents of the file to another file

I have a text file containing the following lines: This is the first line Second line I have a mac Used to have windows Comfortable with both So now I want to grep "I have a mac", and move all the ...
0
votes
0answers
18 views

how to replace a variable in middle of reoccuring commands

I'm in a middle of a merge and I'm trying to find specific variables that went missing in the following way: grep -Rn "<variable string>" <old_branch> | grep -v Binary | grep -v metadata ...
1
vote
1answer
62 views

How to bulk extract bitrate data from videos and output them in a text file?

I have several videos in a folder; ~/Downloads/movie1.mkv ~/Downloads/movie2.mkv ~/Downloads/movie3.mkv I would like to extract the bitrate for each file, and output the data into a single text file,...
0
votes
0answers
79 views

“sh: #: unknown operand” - How do I get rid of this error on shell script?

I have a shell script which when executed works fine, but gives a warning: sh: #: unknown operand In this shell script, I want to comment out the processes namely "process1" and "process2", which ...
1
vote
1answer
52 views

How can I use the grep --color command to highlight brackets?

I want to highlight every [ in any color so i can see the hidden message here: [###[#[[[#[###[#[[[#[[[#[###[#[[[ [###[##[##[[##[#[####[##[[##[##[# [######[##[#[#[#[[[##[##[#[#[##[# [######[##[##[[#[#...
1
vote
2answers
33 views

How to take value as value without considering it as string when we do cat and grep

I have created the utility that need to be run in all the system without any error by creating the required environment. When ever I run the following command it will take the path value from a config ...
0
votes
1answer
47 views

Terminal only outputs last few lines and everything before is deleted

I am using grep to find strings in multiple files. It outputs a lot of text which is what I need, but then terminal just deletes all the output while grep continues working and so I can see only last ...
-1
votes
2answers
37 views

grep and sed only the numbers from a text file's line

I'd like to extract only a number from a text file. It is like: corner_lat: 49.0425000 decimal degrees I am using the following expression : grep corner_lat EQA.dem_par | sed "s,[^0-9]*,," ...
0
votes
2answers
99 views

Regex “.*?” giving same output as “.*”

This the file I am using: Shane is a little to play ball small silly When I use egrep 's.*l' new I am getting the output as Shane is a little to play ball small silly When I use egrep 's.*?l' ...
0
votes
1answer
68 views

Bash: Trouble passing arguments to grep from script

Trying to learn a little of bash scripting and I end up using the 'grep --color -r -n -i SEARCH .' command a lot, so I figured I'd script that. Problem is that I can't seem to pass my search term to ...
9
votes
2answers
728 views

Using AWK to get second column

I can not seem to get the awk command to get the second column of data. Bash Code: filter_data=$(awk "{if(/$filter:/) print $2}" < scanresults_temp.txt) printf "$filter_data \n" The $filter ...
3
votes
1answer
108 views

SHASUMS AND grep in verifying Ubuntu download

I'm trying to better understand the use of "SHA256SUMS" and "grep." The Ubuntu verify and authenticate tutorial uses the following term: "sha256sum -c SHA256SUMS 2>&1 | grep OK" to verify the ...
6
votes
1answer
289 views

Why doesn't grep -r also look in subdirectories when I search with a glob? [duplicate]

Grep with -r was not working for me. I then made a test situation. The directory /home/den/backup now contains a file with the word washer in it. I also made a subdirectory within /home/den/backup. ...
0
votes
2answers
24 views

Splitting data based on semi colon and picking up unique IDs

I have file that looks like this: 26. ZINC19693599 27. ZINC19693598 28. AKOS032468089; ZINC575619353; F6561-5795 ... 29. MolPort-039-321-788; ZINC46759513; AKOS030658283 30. MolPort-039-315-229; ...
4
votes
3answers
322 views

Sorting values and grepping the best score (highest number)

I have a file that looks like this: 7 C00000002 score: -41.156 nathvy = 49 nconfs = 2251 8 C00000002 score: -39.520 nathvy = 49 nconfs = 3129 9 C00000004 score: -...
0
votes
4answers
57 views

How to count the characters within quotes?

Example: Known Data: Total population = "150" Question: Using bash how can I find out the number of characters within quotes? and assign that output to a variable?
2
votes
2answers
361 views

How do I use grep to search for lines containing all words in a list with no specific order in a text file? [duplicate]

How can we use grep to get line(s) containing a group of words, while the order of words is not important, although line(s) should contain all words mentioned in search? I have done that with phasing ...
2
votes
3answers
99 views

How to insert a line break between stderr and stdout

This question helped me understand how to combine stderr and stdout: How to redirect stderr to a file with this command: gunzip -vc /opt/minecraft/wonders/logs/20* 2>&1 But how may one ...
0
votes
1answer
35 views

Find all non-NUL bytes in a file

I am zeroing media with simple pv /dev/zero > ... and want to know if after this command there is any other byte on the media. This would allow me to know that media is corrupted. I assume ideal ...
0
votes
2answers
180 views

Ambiguous redirect, grep command

It was an exercise from one Linux textbook: to give an example both input and output redirected. I found an answer in web: grep \$Id < *.c > id_list But this *.c seems to be the problem. ...
1
vote
2answers
97 views

Parsing Text File By Column Pattern

I was wondering if there is an easy way to use awk or any other command to parse a text file such that a file of something like: Step Temp Enthalpy 0 0 -368 100 1 -369 200 2 -372 300 6 ...
1
vote
1answer
31 views

Is grep 2.25 the most recent version available for ubuntu 16.04? [duplicate]

As I was learning (teaching myself) to use grep, I ran into a problem, some examples I was testing didn't work as I expected. I decided to try to figure out the problem on my own. First I would check ...
0
votes
1answer
41 views

Need help on an egrep regex

I am trying to create an egrep command to grep the number of lines containing a specific text from a text-file but seem to have an error somewhere. The text-file contains several thousand lines and ...
0
votes
1answer
215 views

grep to search word in a file and result given that word with ZIPfile name that contain that word [duplicate]

Here is what I am doing: I want to find which zip files includes this number with number itself for example i want the result be like this : 7505857289 AIRCDR where the number is my search result ...
0
votes
0answers
27 views

Script which checks for a running process [duplicate]

I would like to implement a .sh script which checks whether a process is running or not. I place a cron job which runs the .sh script every ten minutes. If the process is not running, I would like to ...
0
votes
1answer
194 views

How to use a script to end a cron job?

I currently have a cron job that I need to stop on shutdown. During power off, I currently run a "shutdown" script, but I am unsure of how to take the PID number I get from ps -ef | grep cron and put ...
0
votes
1answer
148 views

dpkg --get-selections | grep hold not working in 16.04

I am getting this error The following packages have unmet dependencies: phpmyadmin : Depends: ttf-dejavu-core but it is not going to be installed Recommends: mysql-client E: Unable to ...
0
votes
1answer
91 views

What is uname-r | grep fc?

I was reading a .sh file and find a line written as if[ "`uname -r | grep fc`" == " " ]; then But I don't find the meaning of fc and the whole expression. I am using Ubuntu 16.04 LTS. Thanks in ...
0
votes
1answer
214 views

“ls | grep zip” vs. “grep zip $(ls)”

I'm learning about expansion/ command substitution, and while paying around with an example, noticed that these two commands have different results. For example, if I cd into /usr/bin, and run ls | ...
0
votes
2answers
39 views

Ignoring an output with grep

I am currently using grep to locate a string in a file. However, I get a result I do not want. Example output: user@user:~/tmp$ grep "z=" note > tmp.txt | cat tmp.txt z=0.016728 S_1.4 GHz= ...
20
votes
2answers
2k views

Modifying the color of grep

When I grep something, the result is always in red. I know that the command grep --color prints the result in color, which by default is red. Can I change the color?
0
votes
1answer
57 views

how can i grep something out of a list

How can i grep, sed, cut, xargs or awk the output of lspci I'm looking to get the latency time, the name of the device and the number on the left, whatever that is I've tried lspci -vv | egrep ...
0
votes
0answers
41 views

How can i target punctuation marks when dealing with text

I want to print a file like this after i saved it as file.fw nvram set wl0.2_key4=; nvram set wl0_wds1_ospf=; nvram set wl0_stbc_tx=auto; nvram set wl0_ap_isolate=0; nvram set wl0_ampdu=auto; nvram ...
1
vote
0answers
53 views

Searching a word throughout the system without knowing its address [duplicate]

I want to search a word in my computer and i don't know where it is. For example, i wanna search the word Ubuntu in all texts(word, txt,...) on my pc. In present directory, i use cat * | grep Ubuntu ...
2
votes
1answer
26 views

Running a mv command on large amount of data caused disappearance of other folders [closed]

I messed up by running a mv command on the entire contents of an old external drive to my Desktop without making a destination folder first. I ran sudo mv /my/external/path/* /home/myself/Desktop/ ...
1
vote
1answer
485 views

ack-grep: command not found after upgrade to Ubuntu 18.04

sudo apt-get install ack-grep gives ack-grep is already the newest version (2.22-1) but ack-grep gives ack-grep: command not found It was working fine in Ubuntu 16.04, before upgrading to 18.04
0
votes
1answer
78 views

copying files resulting from using grep into a new folder

I have a question concerning the concatenation of two processes in the terminal. I have a folder with over 50.000 files. I used grep to look for those files containing a specific term: grep -inrl "...
5
votes
1answer
505 views

Bash: info with systemctl

With systemctl status name.service | grep Active I get this info: Active: active (running) since Mon 2018-05-14 21:44:09 CEST; 5s ago How can I get the same info but without: "Active: "?
11
votes
5answers
2k views

grep to return Nth and Mth lines before and after the match

I know that with grep I can use the fields -A and -B to pull previous and next lines from a match. However they pull in all lines between the match based on however many lines are specified. grep -...
2
votes
1answer
54 views

find grep exec, result

If I run the following command find ./dir -type f -newermt 2017-04-01 ! -newermt 2018-06-30 -printf "%TY/%Tm/%Td %TH:%TM:%.2TS %p\n" -exec grep -E -l "pattern" {} \; | sort -n; will return this: ...
1
vote
0answers
22 views

Recently installed ubuntu 18.04 erasing windows, and show no wifi adapter found [duplicate]

on typing : lspci -vnn | grep Network it showed : 03:00.0 Network controller [0280]: Realtek Semiconductor Co., Ltd. Device [10ec:d723] I am using HP Notebook - 15q-by004ax Wifi was working on ...
3
votes
1answer
84 views

how to scan all clients if they contain files with a specific line of text

So I am going to ask for something major here and that is if I can scan from one device all other connected devices to see if they have a specific line of text in any of their files. It is a bit ...
1
vote
1answer
677 views

How to find a line starting with 'a' and ending with 'c' using grep?

I have a file named newfile. The contents of this file are: abc xyz abc Now I want to find lines which start with a and end with c. I enter the following command but the results are not the same as ...