grep is a command-line tool for searching text patterns in files
0
votes
0answers
9 views
Is there is a way to exclude nested subdirectory specified by a path to that dir from grep recursive search?
Or I have to use ack or find for this?
Here's what I want. Say I have this dir structure:
dir/nesteddir/match.txt
otherdir/nesteddir/match.txt
How do I exclude first nesteddir only? Is it even ...
-1
votes
2answers
51 views
Extract text from a file based on some criteria
I have a file which contains records like those:
434419\Teclu\Tudor\1501\9502
187650\Cosma\Sorin\1504\9253
239474\Teclu\Daniel\1502\5245
844936\Gaman\Mihai\1505\4074
942341\Avram\Tudor\1505\4543
...
3
votes
2answers
54 views
grep command doesn't support start '^' and '$' end of line anchors when it's with -Pz
With reference of this Q&A on AU.
Why behavior of GNU grep using -Pz parameters changed and doesn't support start of line ^ and $ end of line anchors?
Is this a bug or correct behavior?
Tested ...
0
votes
1answer
17 views
how to count number of files in a sub-folder having a specific pattern?
I have installed ubuntu as part a college course and I would like to familiarise further with the command line.
I have ton's of text files which I would like to search for specific phrase but I don't ...
2
votes
2answers
42 views
grep the man page of a command for hyphenated options
When I grep the man page of the find command for matches to type it returns a lot of search results that I don't want. Instead I want to use a command that returns only the search results for -type.
...
2
votes
2answers
38 views
count lines matching string in each subdirectory and their subdirectories
In each subdirectory of my current directory, I would like to print the number of line-matches against a string for all files in the subdirectory and its subdirectories.
For example, if I have
cat /...
1
vote
0answers
14 views
Grep --line-buffered, can I search the same buffer with the results of the first grep?
I'm searching a log file in the following format
<date> <connection from: ip> <new connection ID> <info>
<date> <connection ID> <info>
I'm using the ...
3
votes
2answers
258 views
Pipe the result of a cut command to curl [duplicate]
I have a csv file that contains 3 fields per line.
firstname,lastname,url
I'm trying to access the url via the following pipeline:
grep theName file.csv | cut -d, -f 3
then I want to add another ...
1
vote
1answer
20 views
awk - grep multiple rows and print in a specific manner
I have the following content and a file called file.txt
TIMESTAMP 200 J8899
INSTANCES 19 x86_64 False i-xxx1a1a t2.medium True subnet-93b224fb hvm vpc-7b801
STATE 16 running
...
0
votes
2answers
23 views
Loop until grep does not find the text in a file
I have a file named file.txt. The content of the file is as follows
sunday
monday
tuesday
I wrote the below script and it loops just fine if the grep cannot find the pattern that was mentioned
...
1
vote
0answers
16 views
extract multiple sequences from fasta file using sequence headlines
I have a file with filename.fa format with billions of sequences, and I need from this extract 500 sequences with known headlines like such:
@FCC2BDTACXX:2:1308:2823:74384#GGCTACAT/1 ...
1
vote
2answers
30 views
Pipe results of grep into find
I have a logfile with some filenames inbetween other events, which I need to find in subfolders. Same necessity for filenames inside xml files which has to be found inside some folder and subfolders.
...
1
vote
1answer
46 views
How to handle CRLF line endings in grep?
Suppose I have an arbitrary text input that contains CRLF line endings:
$ curl -sI http://unix.stackexchange.com | head -4
HTTP/1.1 200 OK
Cache-Control: public, max-age=60
Content-Length: 80551
...
1
vote
1answer
34 views
grep error: repetition-operator operand invalid
I am trying to compare two files to see if all strings (in this case lines are fine though they are not ordered) from file1 are present somewhere in file 2.
I did a bit of research and it seems the ...
-1
votes
2answers
27 views
Multiple years grep [on hold]
How can I grep exact years in my file which contains world champions from years 1950-2000 but I want only years 1950/60/70/80/90/00? Thank you so much
-2
votes
1answer
32 views
How do I print all words begining with a specific letter in a text
How do I print all words begining with a specific letter in a text? and all words of 4 characters?
thanks
3
votes
3answers
91 views
Checking a script is running [duplicate]
I have a job test.sh schedule to run every 5 mins, and another job test1.sh scheduled to run 12.30pm , @12.30 both jobs will run and is making a deadlock. So I need to check the job test.sh is running ...
1
vote
0answers
15 views
grep, memory issue [duplicate]
I am using grep to search inside the / directory, but I encountered the folowing problem:
root@debian:/# grep -rn allhwsupport
grep: proc/sysrq-trigger: Erreur d'entrée/sortie
grep: mémoire épuisée
...
3
votes
5answers
90 views
Get the query string from URLs in a log file
I have a server log file that contains a number of log entries in the following format:
193.1.172.46 - - [23/Mar/2008:03:57:38 +0000] "GET /robots.txt HTTP/1.0" 404 289 "-" "gsa-crawler (Enterprise; ...
-1
votes
1answer
72 views
Complex multiline search & replace to remove injected code [duplicate]
Note this is NOT a duplicate, though it very much SEEMS like one. Before posting, I extensively tried the other solutions to very similar questions. This case is different because the large multi-line ...
-1
votes
1answer
35 views
grep is outputting the whole file [closed]
I just started using the grep command for the first time. My understanding is that it shows only the lines of text that match the given pattern. In my case grep is showing the entire file but with the ...
0
votes
1answer
14 views
How to extract a XML from log file
I have this log file below, and I would like to extract the XML in the middle of it by using a field as input search <ns12:equipmentId>089471386301077634</ns12:equipmentId>, so the script ...
0
votes
1answer
40 views
searching for a pattern in only crontab scripts [closed]
In the server there are may scripts but few of them are only scheduled, that is they are in crontab.To find all the scripts in all directories I can use this, but i need to search only for cron ...
0
votes
1answer
15 views
How to grep “&amount”? [duplicate]
I need to look for &amount in a file but it throws error -
[1] 25950
amount: Command not found.
Usage: grep [OPTION]... PATTERN [FILE]...
What is the right way to search for it?
3
votes
3answers
66 views
How to delete all occurrences of a list of words from a text file?
I have a file containing a list of words. I want to remove all occurrences of all the words in this file from a big text file.
Example:
File 1
queen
king
Text file sample
Both the king and queen ...
2
votes
3answers
162 views
grep with special expressions [duplicate]
I have some binaries and some .c extension files in my directory.
Here the output using ls
arrays.c basic0 basic0.c fromfb fromfb.c oute oute.c segmen.c
simp simp.c
Here i want to ...
0
votes
0answers
28 views
How '$' works with grep command in bash [duplicate]
According to the man page of grep,
Anchoring
The caret ^ and the dollar sign $ are meta-characters that respectively match the empty string at the beginning and end of a line.
Say I have a ...
0
votes
1answer
26 views
Grep only those lines with “<active>…</active>” whose next line contains specific tag and value
By using grep I only want those lines out of all xml files that contains <active>true</active> tags and the next line after that should be <codePool>community</codePool>.
A ...
1
vote
1answer
19 views
How to compare multiple columns of one file with one column of another and display matches from second file?
I have two files like this:
File 1
apple fruit 10 4
strawberry fruit 22 11
berry fruit 33 33
ball toy 1 12
straw thing 2 33
File 2
strawberry straw berry
rawberry raw berry
I want to compare ...
1
vote
2answers
87 views
Understand why a bash script is not executing main?
I performed a clone of Zcash:
$ git clone https://github.com/zcash/zcash.git
$ cd zcash/
$ git checkout v1.0.1
$ ./zcutil/fetch-params.sh
I'm trying to run fetch-params.sh on both OS X and Solaris. ...
0
votes
2answers
40 views
ssh-add add all private keys in .ssh directory
In my day-to-day, I need to ssh to various machines, all of which I have a different private key for.
When I start a new shell session - only my default id_rsa is added to the ssh key chain - I have ...
1
vote
0answers
17 views
Filter grep result-set by paths containing folder1/folder2 and trim the current folder path from result-set
I have a grep command like below to search for all .xml files containing given string.
grep -rl 'product_list_toolbar_pager' --include='*.xml' --color=always
Now I am using this command on remote ...
1
vote
1answer
52 views
Parsing .txt file to generate .csv
I have a text file with following contents
Torrent file : Linux.Format.-.October.2016.-.True.Pdf.-.Set.1001.[ECLiPSE].torrent
Metadata info : 9968 bytes, 412 pieces, 65536 bytes per piece
Torrent ...
3
votes
3answers
72 views
How to use grep, sort, and uniq to create three fields of output
I am using two files in my command, the first file (file1) is just a file with every letter of the alphabet on individual lines. The second file ($w in my command) is a giant word list. I have to ...
0
votes
3answers
50 views
grep end of several files
I've got a number of log files (20-500) from an application that crashes.
All the log files are from one run of the application - its heavily multithreaded, with each thread writing to its own file. ...
0
votes
2answers
29 views
How to compare multiple files and display the common lines?
I have four files like so:
File 1 contents (tab separated, 3 columns):
applepen apple pen
strawberry straw berry
File 2 contents:
applepen
strawjelly
File 3 contents(This file is sorted):
apple
...
5
votes
3answers
338 views
Extracting data with awk when some lines have empty/missing values
I have a sample as shown here:
input.txt
USERS position ref rslt
usr1 X B
usr2 2980 C
usr3 3323 P
...
-2
votes
2answers
34 views
Print zero if text is not found in a particular file [closed]
I want to print zero if grep is not found in a particular file
grep -A4 " Apple " a.txt | tail -1 | awk '{printf("%f", $4)}' >> out
I tried using if else condition too
if grep -A4 " Apple " a....
0
votes
0answers
23 views
How can I pipe coloured grep output into vim [duplicate]
So I am trying:
grep --color -irn '.' -e "start" and I'm getting my coloured search results with different colours for my files and my search terms. What I can't do is, whenever I pipe this output ...
-1
votes
0answers
26 views
How to get full paragraph details when string matches? [duplicate]
Search pattern "here"
My file's data like
line1
line2
here
line4
line6
line7
line9
here
line11
line12
line13
I need a o/p like this
line1
line2
here
line4
line9
here
line11
line12
line13
-4
votes
0answers
26 views
How to fetch data between two time stamp from a file? [duplicate]
I got this awk '/2016-11-04 00:01:00/,/2016-11-04 00:05:00/' already, but how we can pass the user entered values in awk command via variable
[java] 2016-11-04 00:00:49,752 - Received Event
[java] ...
1
vote
1answer
38 views
How to find a hidden string in multiple directories
I have bunch of directories with each and every one of them containing a file.
Now some of these files are hidden.
I need to find a string that's in one of the hidden files.
I tried
fgrep -r "*...
2
votes
1answer
31 views
Merging two CSV compared by a specific column only
I want to compare two CSV files with the following format. They not have headers. I want to compare them by a specific column (in this case, the 2nd one).
The source CSV files around 4-5GB, so ...
0
votes
1answer
67 views
grep works in bash script but not in terminal
I have a strange behavior in my terminal.
The following command prints nothing to my terminal:
comment=$(
cat /usr/share/applications/brasero.desktop |
grep '^Comment=' |
grep -Po '(?&...
0
votes
2answers
65 views
How to grab the head section of a website using the curl and grep command?
I'm taking my Linux+ midterm and I'm stuck on a question where I'm supposed to copy the head section including the tags and output it to a file. My midterm is due on the 5th so it would really help if ...
2
votes
4answers
68 views
Print only unique lines that appear last in logfile based on date/time
I'm working with a logfile with the following format:
Oct 12 01:28:26 server program: 192.168.1.105 text for 1.105
Oct 12 01:30:00 server program: 192.168.1.104 text for 1.104
Oct 12 01:30:23 ...
2
votes
1answer
45 views
grep search + next line
With the grep command, I found the text I need as follows:
grep 'C02' ~/temp/log.txt
Now, whereever I find the desired string, I would like to print the line following the found string.
For example,...
1
vote
1answer
43 views
how to get rid of unwanted lines? while loop?
I have wrote this code:
#!/bin/bash
filter(){
grep -Ev "INFO" /app/me/logs/$1
}
filter "$1" > /app/me/logs/${1}.filtered
cat /app/me/logs/${1}.filtered
so what it does is that it eliminates ...
1
vote
3answers
51 views
Search for a string in a file and rename multiple files to the results
I am attempting to recursively search through a list of files and if the file contains a string, rename the file to the grep results of said string.
The sample files contain a the following content:
...
0
votes
2answers
28 views
Dumping files based on specific word
I have a file:
begin
path: good
take this way
easier path
end
begin
path: bad
You shouldn't go there
end
begin
path: good
Very smooth
end
begin
path: bad
you may face ...