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

-1
votes
0answers
17 views

Linux permanently hung after running a grep command on “/sys/*” directory

I ran the command: sudo grep -r -i RETP /sys/* On two systems: Oracle Linux 7.5 server (256 GB RAM, 2 Intel® Xeon® Gold 6142 Processor) and on my desktop PC with Ubuntu 18.04 (16 GB RAM, Core i5-...
-4
votes
0answers
32 views

How to grep a second pattern and print the line till the next third search pattern [on hold]

How to find or search PATTERN1 and then search PATTERN2 and print them both later i want to search PATTERN3 and Print the whole content or section between the search PATTERN2/PATTERN3 (Note Pattern1/...
-1
votes
0answers
24 views

Highlighting special errors in a log file [duplicate]

I tried to find out how I can highlight some errors in a log File. At the moment i got this: tail -f /data/log/...... so I can see the the errors direkt on the monitor. I would like to see "err-...
0
votes
3answers
53 views

Text selection in Unix using sed

I want to select a particular part of a text file and print it / store in another file. Selection starts when a particular pattern matches and ends when another pattern matches. And I have to do it ...
6
votes
1answer
69 views

Removing words comprised of upper and lowercase letters?

I have file called file.txt. In this file there are words composed of upper and lowercase letters, also there are words consist of upper or lowercase letters and numbers. I would like to filter this ...
0
votes
1answer
32 views

Print everything after a grep? [duplicate]

Is there anyone who can help me to understand how to print everything after a certain line? I got a really big logcat (since 2016) and I'm interested in printing everything (all the rows) after a ...
1
vote
1answer
40 views

grep fails with variable but works if variable is spelled out

I have two comma delimited files I will read 1 line from file 1, I need to find matching lines in file2 including the comma's in between If I do it literally by typing the line (i.e. copy-n-paste ...
5
votes
2answers
374 views

using grep --recursive, how to exclude specific line with the 'unwanted' and 'wanted' word in it?

I'm currently building my dotfiles and I want to list all TODO: ... comments in my project's directory, I created a bash alias to do this: alias mytodo='grep --recursive "TODO: "' It works well, ...
0
votes
0answers
18 views

How to use grep to search for and count words of two different lengths within a document

I am trying to search within a text file for words that are either 8 or 12 characters long and then count them. I understand that I can use the command grep -o -w "\w\{8\}" my-file.txt to find ...
0
votes
2answers
52 views

Searching for files within subdirectories?

I have a tree of parent folder and subfolders. The subdirectories have similar names. I would like to search for files stored in the sub-directories. How can I do that? For example: Parent-...
-1
votes
2answers
42 views

Extract lines in a log file that are greater than a value

I have filtered a server log, and would like to save the IP + code to a new text file that only contains lines where the code is above a value of 1000. Example log file: 1.1.1.1 1000 2.2.2.2 2000 3.3....
0
votes
1answer
68 views

Grep exclude result + 3 lines from output [duplicate]

I would like to exclude matching pattern and the following lines from the output files. When I use : cat test1 | grep -Fx -A 3 -f test1ignore The file test1 is here: https://pastebin.com/...
8
votes
4answers
721 views

Count lines wider than 80 columns, taking tabs correctly into account

To count lines wider than 80 columns I am, currently, using this command: $ git grep -h -c -v '^.\{,80\}$' **/*.{c,h,p{l,y}} \ |awk 'BEGIN { i=0 } { i+=$1 } END { printf ("%d\n", i) }' 44984 ...
5
votes
7answers
155 views

How to compare the same word between multiple files?

I would like to count the same words across multiple files then show in which file they are. File1: This is so beautiful File2: There are so beautiful File3: so beautiful The desired output 1: ...
-1
votes
2answers
49 views

grep only whole words starting with get_ [closed]

In my file I want to grep whole words which start with get_. Example: o/p should be: set_output_delay -clock clk_i 3 [get_ports xyz] set_clock_latency 0 [get_clocks clock] set_disable_timing [...
-2
votes
1answer
25 views

How to search for a pattern of words in shell script?

I want to search for a pattern of words in a text file. The pattern is like: Summary: ........... Fault The dots indicate anything can come in between. How can this be done in shell script?
2
votes
3answers
93 views

how to mask email address joebl**@******.*** using sed/awk/grep/etc [duplicate]

I have some emails where I would like to mask all characters except the last 2 before the @ sign and mask everything after that. For example: <joeblow@joeblow.com> Desired output: <joebl**...
1
vote
1answer
33 views

How to download all images with the full resolution (i.e. svg) from a single wikipedia article [duplicate]

I was asking myself how to download all (.svg) images from a single wikipedia article without doing it manually for each single image. Wikipedia is offering images in different resolutions and ...
1
vote
2answers
50 views

Finding filenames that end in a specific character with or without an extension [duplicate]

I have a bunch of files in a folder that all end in a different version number, like 1, 2, 3, etc. Some of them have extensions, some of them don't. Is there any way I could use a command like ls, ...
1
vote
0answers
34 views

How to tail and grep log file, combine into a single line and pass as argument to another command

Using the following command, I managed to fetch error messages below (it's 3 lines). $ tail -f -n 0 error.log | grep -A2 --line-buffered "Internal server error" ! @79884flo2 - Internal server ...
5
votes
2answers
396 views

Grep words with special symbols

How do I grep this? (Including the special characters) "Limit reached."[\n]" I tried back-slashing the special symbols but end up not working, like this: grep '\"Limit reached\.\"\[\\n\]\" ' I ...
0
votes
2answers
40 views

How to grep the rows with same column in different files and print specific column and add onto the original file? [closed]

Here is the text files we have: file1.txt A B C D 4 9 5 8 file2.txt: H I J K L M N O P Q R 1 2 3 5 8 9 5 3 3 2 4 4 7 8 9 5 6 8 9 0 8 7 7 8 0 7 4 7 7 9 0 6 7 2 7 9 5 7 9 0 7 6 5 4 I want extract ...
0
votes
1answer
51 views

Error with grep and find

When I try to execute : $ man find | grep "-mtime" I get this message back : grep: invalid max count I wonder how to search with the -
0
votes
2answers
42 views

Filter out 2nd occurance of text betwen quotes with sed? [duplicate]

I have a grepped output of a file like so: "name" "Andrew Spokes" I want to extract the name by piping the output of grep through sed. My expected output would be: Andrew Spokes I require all ...
1
vote
4answers
96 views

How do I grep file paths out of a text file?

I have a file that has a list of paths like so: "1" "/user/bin/share" "2" "/home/user/.local" "3" "/root/" Is there a way to extract just the paths? I dont want the numbers or ...
1
vote
3answers
137 views

How to move a line from a file to the other file on the basis of pattern matching?

I want to move lines from a text file into another text file. Those lines contain a word beginning with an underscore. This word is located on the sixth field of the lines; fields are separated with ...
0
votes
2answers
47 views

How to extract number from the below string which is the output of a command?

I want to extract message number which we get on executing command mailx -H. I want the message numbers of unread and new messages only. I tried with the below command: mailx -H|grep '^ [UN]'|cut -c ...
20
votes
3answers
2k views

grep doesn't output until EOF if piped through cat

Given this minimal example ( echo "LINE 1" ; sleep 1 ; echo "LINE 2" ; ) it outputs LINE 1 and then, after one second, outputs LINE 2, as expected. If we pipe this to grep LINE ( echo "LINE 1" ; ...
1
vote
1answer
27 views

Grep regular expression to show only serial numbers (defined length containing Alpha & Digit) in CSV File

I have a lot of (huge and chaotic) CSV files with a bunch of (Cisco) serial numbers. My goal is to extract them (BTW: And to call the Cisco API later on for getting service/support coverage feedback)...
3
votes
4answers
57 views

Move files into separate directories based on grouping defined in a CSV file

RELATED: Move all files with matching prefixes to folder based on a csv list I have a two-column CSV file (comma-separated values), with headers: "id","group" "F1256","old" "E51651","new" "X56369","...
2
votes
1answer
38 views

Expect wigs out when I use the single quote in [exec ls -h | grep '\.foo' ]

I am trying to store a list of specific files into a variable in expect. In my script, I am trying to compile files that have different file extensions, like .foo, .bar. In this example, I have the ...
1
vote
2answers
37 views

How to list all the processes assigned to a user on a cluster

We have a cluster in our university controlled by SLURM. The issue is that I have observed sometimes some of the resources are not being realised even though they do not show up in the squeue command. ...
0
votes
3answers
45 views

How to remove lines from a text file that has specific value in a column through input file?

I have a pipe delimited file as below. data.txt ESP|041336|46566|NY|CA ESP|041337|46566|NY|CA ESP|041338|46566|NY|CA ESP|041339|46566|NY|CA ESP|041340|46566|NY|CA ESP|041341|46566|NY|CA I have ...
0
votes
2answers
41 views

Copy line in text file and add modified line to the end of line in same file

I would like to copy line in text file edit it on the fly to replace all / to | and paste in on the same line in the same line. I have the first line in the text file: http://webpage.com/(name-never-...
0
votes
1answer
52 views

Why is GREP outputting BINARY FILES rather than a SINGLE FILE named “0.jpg”?

I love BASH but am struggling with GREP. My goal is simple: GREP my Desktop files for “0.jpg”. MY BASH CODE: $ pwd /Users/jennalusche/Desktop $ grep "0" *.jpg EXPECTED RESULT: 0.jpg ACTUAL ...
6
votes
4answers
162 views

grep'ping files for multiple strings (not on the same line)

More often that I like to admit I look for a file that contains some strings. Currently I do: grep -rl string1 | xargs grep -l string2 | xargs grep -l string3 Is there a tool that does this ...
1
vote
2answers
64 views

grep : find bigger string in small string

I am writing a small shell script to receive an input and match against a text file. However, the input would be a bigger string than the string in the file, against which I want a match. User ...
2
votes
1answer
98 views

count all specific words that ended in each line

how to count all words that ended with ".wsp" in the file more file /application_1532998892988_0207/driver/BlockManager/memory/remainingOffHeapMem_MB.wsp /spark/application_1532998892988_0207/driver/...
1
vote
1answer
34 views

Skip text in output with grep in perl mode

I have text like this: blah, blah <foo:ImportantText> blah blah time=1.234 blah blah blah, blah <foo:AlsoImportant> blah blah blah time=9.9 blah blah blah, blah <foo:ImportantText> ...
0
votes
1answer
63 views

Bash script to monitor log, match keyword then send commands [duplicate]

#!/bin/bash sudo tail -fn0 /home/main/time.log | grep -o --line-buffered 'garage\|garden\|porch' | head -1 | while read line; do sudo pkill -f porch.sh & sudo pkill -f garage.sh & done I'...
0
votes
2answers
41 views

Compare two files with using awk

I have 2 files. File 1 contains :- emcas_biaas_dev=-628 emcas_brs_ba=-32 emcas_cc_analytics=246 emcas_edservices_bi=312 emcas_edservices_dev=-159 emcas_engr_usd=1519 emcas_engr_xio=-67 emcas_fin_bi=...
3
votes
4answers
266 views

Extract addresses separated by semicolon and print each address in a line

I have a file with the following input. The numbers separated by dots represents addresses. Any number in address can be one or more digits as follows: [112.112.112.112;3.3.3.3;44.44.44.44] [6.6.6.6;...
-1
votes
0answers
62 views

Check if all property has value in property file. If yes need to create a file

I need to check if all the properties in a property file has values. The property file will contain namenode, paths, and many other variables used in oozie workflow. I need to check if the namenode ...
1
vote
1answer
24 views

batch rename folders with value from json value in package.json

This is a bit of a crazy one, but I am wondering if it is even possible. I have maybe 300 folders in my /var/www folder that were all renamed to the same name [Name](Num) so kindred (19) for example. ...
1
vote
3answers
79 views

Display lines in last 10 minutes with specific pattern in logs

I need to display lines with Error occurred in last 10 minutes of a log file. Aug 26 10:50:42 Normal line. Aug 26 10:51:23 Normal line. Aug 26 10:55:33 Error line. Aug 26 10:56:45 Normal line. Aug ...
1
vote
4answers
47 views

How to process a column's multiple strings

I have a comma separated file that looks similar to his format: aa.com,1.21.3.4,string1 string2 K=12 K2=23 K3=45 K4=56 bb.com,5.6.7.8,string1 string2 K=66 K2=77 K3=88 K4=99 I want to take ...
-1
votes
1answer
42 views

Finding files with specific content, user and permission

I need to find the name of the file which is owned by the root user, and has global read, write, and execute permissions. Lastly, it contains the following contents "immerse" this is my command line ...
2
votes
2answers
27 views

grep buffer for previously executed command output [duplicate]

Is it possible to grep the buffer? For instance if I execute a build process in my VxWorks shell, linux shell, etc, is there a rolling file that contains buffer (e.g. data while scrolling)/previous ...
11
votes
4answers
693 views

How to put a string search with grep command into if statement?

I want to search multiple strings in two files. If one string is found in both files, then make something. If one string is found in only one file, then make another thing. My commands are the next: ...
0
votes
2answers
40 views

Grep Multiple Files with Dates in FileName for Certain range of Dates

I have a bunch of files with filenames like "Logger.2018-08-04_23:59:59.csv" and I want to grep a bunch of them at once, but only in a certain date range, e.g. 8/04-8/17. How can I do this? I tried: ...