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 tool for searching text patterns in files

0
votes
3answers
35 views

count the values in column but consider only lines after matching first occurrence of a matching pattern

I need to count the values in 2nd column from the output of some command. However, the challenge is I need to consider only those lines which comes after a line containing specific patter. For example:...
0
votes
3answers
31 views

Grep/Awk for Value Between

So I have a text file with lines like this: http://sg.ovies.m/.ss/ (Status: 200) [Size: 128] http://sg.mo.v/.dev/ (Status: 200) [Size: 12328] http://som.b/.hal/ (Status: 200) [Size: 1238] http://m.cb/...
0
votes
0answers
21 views

Grep and run command in every folder where a file contained a match

I'm looking for an elegant way to execute a command in every folder where grep has found a match in a file. Much like find's -execdir flag, except that find only searches folder/file names, but not ...
0
votes
1answer
29 views

Going to exact line in CSV without going over all lines?

I have a large CSV file, and I need to go "directly" (one operation) to a specific line of that file (lets say line # 103500). I was initially thinking of doing cat over the file, and reading the ...
2
votes
2answers
56 views

How can i remove duplicate files that contain 2 matching strings but keep the rest?

I have a problem that i can not think how to solve. I have a directory that contains 1000's of files which each contain a URL with a URL parameter: File 1: example.com/car/?wheel=tyre File 2: ...
0
votes
2answers
34 views

Working with grep

I am try to fetch all the links from materialdesignicons.com! I do the following: curl -X GET https://materialdesignicons.com | grep -i "<link href=" | grep -v "<link href=" But it doesn't ...
0
votes
1answer
11 views

Isolate portion of line from log file, then print to screen

If I have a file that updates a record count every 5 minutes, the output looks something like this: timestamp name of log file dataset record count 8600 timestamp name of log file dataset record ...
-2
votes
2answers
30 views

Fetch line which contains only some specific symbol and number

I Need only those records from below file which contains Symbol like "+" and number and characters. 285627 AA283244 278178## 295456+ asdfasdf{ asdfasdfasdf I tried below code but it gives all ...
0
votes
3answers
50 views

How to match for an empty string in a grep pattern search?

I have a set of files containing boot variables from several cisco switches in the network. I have an requirement to filter only the switches with the boot variable empty on the next reload and print ...
0
votes
2answers
30 views

Can't run parallel zgrep with regex

When I run this: find . -name "my.log*.gz" -print | \ parallel zgrep -e "\(text1\|text2\).*Exception" to find all lines that match /(text1|text2).*Exception/ in all files in the folder, I get this ...
0
votes
1answer
45 views

How to grep using gcc to find definitions in standard librarys [closed]

I have found in my project a type definition, which is definitely from a standard library. Lets say the definition is called uint64_t I know #include <stdint.h> #include <string.h> #...
0
votes
0answers
14 views

How to create separate files based on first column value? [duplicate]

It is tab separated 3 column file. I need to create separate files based on first column value Input: 194501 CAD 1.47421052631579 194517 CAD 1.39578947368421 194520 CAD 0.949473684210526 194501 ...
0
votes
2answers
34 views

grep stringset as a single line

Let say in a text file if I do grep FINAL *.msg it returns FINAL COMPUTATIONS: Elapsed Time: 000:30:55.65; CPU Time: 000:30:26.53 FINAL COMPUTATIONS: Elapsed Time: 000:28:11.77; CPU Time: ...
0
votes
3answers
56 views

How to grep a line who has execution time greater than X

I have this line in my log invokeSuperLambda execution time:xxs Where xx is the time of execution and s is a static letter When I run this on my log file grep -a "invokeSuperLambda execution ...
0
votes
1answer
45 views

Search strings in (.gz) zipped folder with files in it [closed]

Need to search strings in (.gz) zipped folder with files in it. Sample Folder - PROD_009_010919_0110.tar.gz Files inside - PROD_009_010919.log01, PROD_009_010919.log02, PROD_009_010919.log03..........
0
votes
1answer
45 views

How to use a Bash Script to move and rename files with grep

Hi I an FTP folder called Input where I get sent files which look something like this: "Guide to Iceland _ Chen-ping Wang itinerary T-987654987.pdf" "Guide to Iceland _ T-123654875 Chen-ping Wang ...
0
votes
1answer
39 views

Find, grep and then create table

I am trying to find all *.md at ${PWD}, then grep for lines beginning with title: and print it along with the absolute filepath -H and the line number of the pattern match -n, then I try to output the ...
1
vote
3answers
78 views

grep: --exclude-dir don't work

I want to tell grep, on Debian, not to search through files in /proc or /sys. But if I use: --exclude-dir=/proc or --exclude-dir={/proc,/sys} or --exclude-dir=/proc --exclude-dir=/sys Then grep ...
1
vote
1answer
42 views

How to grep only the channel number

From : sudo iwlist wlan0 scan | grep Frequency I get Frequency:2.412 GHz (Channel 1) Frequency:2.412 GHz (Channel 1) Frequency:2.462 GHz (Channel 11) ...
1
vote
1answer
18 views

cycle through reverse search in a custom command history file in bash

I added a line to ~/.bashrc file which appends all issued commands to ~/.bash_eternal_history file in a date directory history-number command format, such as: 2019-01-08.23:59:32 /home/sport/...
2
votes
1answer
28 views

wget image problem for daily wallpaper script

i have a script (that Nuno wrote) to wget an image from one particular site and set my wallpaper. however i can't seem to modify it to be able to wget an image from this site: chromecast images in ...
2
votes
2answers
36 views

Search for three consecutive newlines?

I know that squeezing multiple blank lines can be done using cat -s (and squeezing all blank lines can be done using tr -s '\n'), but I'm curious how to search for this condition in a stream of input. ...
2
votes
1answer
41 views

How can I grep for empty functions?

I'm recursively looking in a directory for all functions containing only a blank one-line comment, such as the following: public function index() { // } I tried grep -PR "//$" * with no luck.
1
vote
1answer
27 views

grep string from alphabetically last files in subdirectories

I need to look for the string "Total CPU time used" in a set of files that are generated in an iterative calculation within a great number of subfolders called folder_A, folder_B, folder_C and so on. ...
1
vote
1answer
59 views

Search within man pages of POSIX Programmer's Manual

I would like to search for POSIX functions matching the restrict keyword and my idea (open to other ideas) is to search the SYNOPSIS sections of the POSIX Programmer's Manual for \<restrict\> ...
0
votes
2answers
36 views

delete pattern at least 5 numbers non consecutive

I have a file with about 7 million passwords with mixed Lower Upper digits all have the same length 8 symbols I want to remove the passwords than contain 5 or more digits not necessary consecutive:...
0
votes
3answers
47 views

Extract particular string from stream

I have a file in which snort signatures are stored, I need to extract Bold ones "sid" and CVE number from that signature, here is a sample signature alert tcp $EXTERNAL_NET $HTTP_PORTS -> $HOME_NET ...
1
vote
3answers
50 views

Extracting a single line containing the highest value in a given column from a text file from each consecutively numbered sub-group/family

Within my text file, I would like to take the line containing the highest value present in column 3, from each consecutively numbered family (i.e. family_1, family_2 etc.) from column 2 and input ...
4
votes
6answers
108 views

How to edit the entire file after match a grep pattern?

To simplify, I want to edit the whole file after matched pattern, example of a file: $ cat file ip=x.x.x.a mask=255.0.0.0 host=a ip=x.x.x.b mask=255.0.0.0 host=b ip=x.x.x.c mask=255.0.0.0 host=c ip=x....
0
votes
1answer
22 views

extracting actual numbers and not cutting others

I have a log file that I'm extracting 7 digit numbers and 5 digit numbers. grep -ao '[0-9][ ]\{7\}' /var/log/Bridge.log.1 | sort | uniq -c This works and extracts my 7 digit numbers. When I use this ...
3
votes
2answers
110 views

Grep does not read the entire file

When grepping log files, I often experience that grep does not find matches closer to the end of the file. Example file For example, running grep -n "demodulator_process" 2018_12_22_13_04_adfags-...
10
votes
4answers
1k views

Move all files NOT ending with .txt [duplicate]

In the directory /home/username/data I have both files and directories. Some of these filenames end in .txt (to which I'll refer as text files), others don't. The same happens in the subdirectories. ...
3
votes
3answers
138 views

Grep between patterns on separate lines or single line

So what I would need is for grep to match only the text in between (and including) my match pattern. So something like this (don't mind the text, it's just some garble :D): asdgfasd gasd gdas g This ...
-2
votes
1answer
53 views

Show only lines which contain numbers [closed]

I have a file with the following lines: irakli1 iraklikairakli ikarkalsi1 iarksldisrii3 irakli and I want to show only the lines which contain numbers. I tried this but it is not working: sed -n '/...
2
votes
1answer
504 views

How to grep '$$$$$'? [duplicate]

I want to check the absence of the following sequence of characters $$$$$ (i.e., 5 dollar signs) in a json file using grep as it has been used instead of comma to separate fields and I need to make ...
0
votes
3answers
57 views

removing “na” from a column and collapsing the row

I would like to remove rows that have an "na" file 0.000 0.000 0.055 0.036 0.003 0.002 0.000 0.002 0.002 0.002 0.000 na na 0.000 0.000 na 0.002 0.002 0.003 output 0.000 0.000 0.055 0.036 0.003 0....
0
votes
1answer
16 views

Extract rows from file_1 based on matching the first two columns from a file_2

File_1 ##chr pos rc allele_count allele_states deletion_sum snp_type most_variable_allele diff:1-2 diff:1-3 diff:1-4 diff:1-5 diff:1-6 diff:1-7 diff:1-8 diff:1-9 ...
-1
votes
1answer
38 views

grep -v is not excluding the strings [duplicate]

im trying to narrow down a flag to catch by removing strings with certain unwanted words so i use cat $(find / -size 33c -group bandit6 -user bandit7) | grep -v 'Permission' but my results end up ...
1
vote
4answers
92 views

Count the number of files and folders containing a certain string

Let's say I'm in the Desktop directory and want to count the number of files and directories whose name is exam. It should also count the files containing the string exam. So to sum it up I need to: ...
1
vote
1answer
70 views

Grep a string in a file in bash [duplicate]

When I grep a string in a file, it gives me a match. However, when I do it in a bash script, it doesn't work. $ cat files_android.txt 000d07dfe5016314c98b869c19c7f986b5db57db49ac76d16a5d2f5861a35072 ...
0
votes
4answers
76 views

grep and cut text from unstructured file?

From below 3lines I need to grep and cut jar file name only. How to grep jar name from the line and cut from there. Downloading:https://repo.maven.apache.org/maven2/org/springframework/spring-aop/5....
2
votes
1answer
51 views

Use regex for file matching, not string matching

I'm trying to figure out how to use grep to search for for a specific string, (for the sake of simplicity) say "9", and I want to search for this, again for simplicity, on all files containing the ...
0
votes
1answer
29 views

disable bold font and coloring in grep

I want to use the output of command: fdisk -l | grep -i "/dev" in my bash script. But the problem is that it bold and highlight/color the matched output. I don't want that. I only want to print ...
1
vote
1answer
47 views

tar --list only top level files and folders

using tar --list --file=x will list all files and folders. I am just looking to list the top level files and folders does anyone know how to do that? alternatively, does anyone know how to list only ...
0
votes
2answers
41 views

Find files (not) containing text pattern on a specified line

I'm trying to search through a set of text files and return the names of files that on a specified line contain a text pattern OR do not contain the text on the specified. In my case I need to return ...
0
votes
1answer
28 views

Match exact string in column on bash

I have situation below, but I want only that column two is only READY and nothing else. kubectl get nodes | grep "\<Ready\>" 10.5.0.11-c76ed Ready,SchedulingDisabled 10.7.0.13-d5bba ...
1
vote
2answers
32 views

Using find, how to classify like ls -F ? (directories with a trailing slash)

I use find to get a list of files, then I grep it to do a path matching : $ find pc* | grep -i arthur pc6/arthurv/untitled-2.py pc6/arthurv/untitled-3.py pc6/arthur.py pc9/Arthur 4C pc9/Arthur 4C/...
0
votes
1answer
29 views

How to filter text, removing lines where a specific position is empty

# lshw -c network -businfo Bus info Device Class Description ======================================================== pci@0000:03:00.0 enp3s0 network I210 Gigabit ...
-2
votes
1answer
56 views

grep dates in a text file to less than 30 days old and move to a new file [duplicate]

A script that should look out for texts with a date inside the file thats 30 days older than the current date then move to another file like the $ awk '$NF <= "2018-05-01"' ip.txt but need a ...
0
votes
2answers
23 views

How to grep all result such that the sub-pattern may or may not containing in the target pattern?

Suppose I have search the string which give like the following result anything1.knownKeyWord anything2.knownKeyWord anything3[1].knownKeyWord How I can write generic syntax for grep such it match ...