grep is a command-line tool for searching text patterns in files

learn more… | top users | synonyms

1
vote
1answer
32 views

How to Find All .tex Files in Directories in Recurse Grep?

I want to expand the recursive search of symlinks to include only .tex files find . -type l -name "Math*" -exec grep -d "recurse" word {} +. Failed pseudocode 1 find . -type l -name "Math*" \ -exec ...
0
votes
0answers
25 views

Return true or false if files matching wildcard pattern are in a specified directory [duplicate]

I'm trying to adapt some code to return true or false if files matching the *.log pattern exist in the $DIRECTORY variable. I had it returning true or false at the directory level for any files: if ...
9
votes
4answers
216 views

Find files that contain multiple keywords anywhere in the file

I'm looking for a way to list all files in a directory that contain the full set of keywords I'm seeking, anywhere in the file. So, the keywords need not to appear on the same line. One way to do ...
0
votes
2answers
54 views

How to grep stderr? [duplicate]

How do I grep this command that includes a wildcard? How do I grep stderr? The grep does not seem to do anything: $ less /Users/raine/.nvm/versions/node/v5.5.0/lib/node_modules/* | grep "Not a file"...
1
vote
1answer
20 views

How to filter the success message when using nc port scan

I used following command for port scanning of my machine nc -zv 192.168.1.1 1-100 but I want to filter only succeeded message from following output.Hence i used the following command nc -zv 192....
-4
votes
3answers
35 views

Bash - Print lines containing at least all vowels in any order but no consecutives [solved]

The problem is to write a script that takes a file as argument and prints all the lines that contain -at least- all the vowels , -regardless of ordering-, but with [no two same consecutive vowels]. e....
2
votes
2answers
40 views

Get only the size of a mounted filesystem

I want to get only the total size of a mounted filesystem. But the catch is that I only know about the mount point. So, I thought of using the df command. To get the size of this mounted filesystem, ...
1
vote
2answers
32 views

Generating strings of words with space delimiters from cut statement

I am new to bash. When I run the following command: grep "type" /root/myFile | cut-d'=' -f2 I get the following: 102 304 503 442 I want to store the contents of the first command into a ...
1
vote
4answers
56 views

Getting substrings in between delimiters multiple times from one string without looping

I have looked all over for a solution to this, but I couldn't find one. I am using qstat -x to pass a large string of job information. The output from qstat -x is in XML format. The substrings I am ...
3
votes
1answer
27 views

How can I list all layouts and corresponding variants that don't use 3rd level symbols?

I need to list all possible xkb layouts and their respective variants that do not use 3rd-level symbols. Manually review of all files in /usr/share/X11/xkb/symbols/ directory is crazy, there maybe an ...
7
votes
5answers
637 views

How to find lines that begin with **

I need to find if any lines in a file begin with ** . I cannot figure out how to do it because * is interpreted as a wildcard by the shell. grep -i "^2" test.out works if the line begins with a 2 ...
-3
votes
2answers
65 views

How can grep for files that end in %0x9

I need to find files ending with the character %0x9. How can I do that?
6
votes
4answers
639 views

I need to find all users home directories listed using grep from /etc/passwd

I have a question similar to another one on this site where the individual had to find a list of all users using grep or awk from /etc/passwd. That worked for me but I've tried translating it to find ...
1
vote
2answers
56 views

Count the number of lines found by grep

I want to know how many instances of a pattern are found by grep while looking recursively through a directory structure. It seems I should be able to pipe the output of grep through something which ...
1
vote
3answers
84 views

Find and Replace with command line

my log.txt file includes ... mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 ... how can I replace mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 with mynetworks = 127.0....
0
votes
1answer
15 views

elinks -dump not finishing on long url

So I have been working on a little script to alert me when an artist releases a new album using amazon and elinks. Problem is that for some reason elinks will stop half way through the -dump command ...
0
votes
3answers
20 views

How can I sort specific lines of strings from this file on my Ubuntu Server?

I have a very long file containing around 2,000 groups of information that look like this: http://pastebin.com/raw/vKxRNviT I need to organize them by dollar-balance from highest to lowest. I only ...
-2
votes
1answer
50 views

filtering pattern in a file using sed or grep

I'm new to Linux. I'd like to store all the unique usernames present in the extended.log file into a new file using the commands awk, grep, and/or sed. The following are the field-names in my file, ...
1
vote
1answer
50 views

Why getting these “Permission Denied”s in POSIX find-grep readable?

I do in Posix find $HOME +perm 0666 -type f -exec grep -l "XSym" {} \; but get this which I do not understand find: ‘/home/masi/.dbus’: Permission denied grep: /home/masi/.viminfo: Permission denied ...
-1
votes
1answer
28 views

Read file and write output in another file using shell script

My input file is: Employee e_id e_name 100 abc 101 xyz 102 pqr Salary e_id e_salary 100 12345 101 67890 Dependents e_id depp1 depp2 100 qwer tyui 102 asdf ghjkl I want the output line by line ...
2
votes
1answer
155 views

Read from and append to file at the same time while preserving end-of-line

Conceptually I have an easy task... I have [loosely] structured data in a file: Testing: debug, default CXXFLAGS <100's of additional output lines> Testing: release, default CXXFLAGS <100's ...
1
vote
2answers
34 views

PGrep in my shell script: not counting the script itself

This is the behavior of pgrep on my FreeBSD script: luis@Balanceador:~/Temporal$ cat test.sh #!/usr/bin/env bash pgrep -fl "test.sh" luis@Balanceador:~/Temporal$ ./test.sh luis@Balanceador:~/...
3
votes
2answers
353 views

grep: How to find Closing Bracket?

One part of /usr/share/X11/xkb/symbols/us starts with xkb_symbols "dvorak" { and ends with the closing curly bracket }; which line-number I want to find. partial alphanumeric_keys xkb_symbols "...
4
votes
4answers
43 views

Generate line number / “index” within a range from a date seed value

I'm trying to create a bash script to display a word of the day (random for each day). I have a dictionary file that on each line has a word and its definition. I'd like to use date to get a unique ...
5
votes
1answer
280 views

Why won't grep work in this command?

I have GTA San Andreas running in Wine, although when I exit the game it hangs in the terminal, and the process still has leftover resources, which causes it not to exit. So I've made this command ...
2
votes
2answers
76 views

Grep for dates older than 14 days in a file [duplicate]

I'm trying to find a way to grep how many messages in a file are older than 14 days and have a value of number of results return Example going with today's date of 20160616. $grep 'Put Date' filename:...
1
vote
1answer
43 views

How could I search pattern of one file in to another and save the result of each pattern in new file

I would like to search the patterns of file1 in file2 and the save the result of each pattern in new file. I know how to do do it wiht all the pattern to be search in file 2 and save the results with ...
0
votes
3answers
53 views

Find-grep for List of .tex Files?

My document.tex where I want to get the list of files, and grep those files with the term gastric \subimport{}{1.2_protocal_answers.tex} \subimport{}{2_protocol_answers.tex} 1.2_protocal_answers....
1
vote
2answers
33 views

Can anyone explain this expression piece by piece please? grep '\([aeiou]\).\1'

I found this expression for a homework assignment that will "print all lines containing a vowel (a, e, i, o, or u) followed by a single character followed by the same vowel again. Thus, it will find “...
1
vote
3answers
61 views

grep on interactive program

I have an interactive shell-like program, that outputs a lot of irrelevant error messages, that confuse our customers. Each of these error messages are full-line messages starting with "%". So the ...
1
vote
1answer
36 views

How to find files their names, name of files are in one file?

I know how to find and concatinate pdf file. I did with the follwoing code. pdfunite *.pdf output.pdf But the problem is I have list of file names in one file say filenames.txt and I would like to ...
3
votes
2answers
72 views

Save the matches of grep as an array

I have a file with the following contents: FILETYPE=A:B:C:D How can I grep out A, B, C and D and save them as an array in a ksh script on Linux? I tried FILETYPES=`grep "FILETYPE" ${CONF_FILE} | ...
0
votes
2answers
79 views

how to exclude string that include space by “grep -v” [closed]

I have a script that runs by using bash -c and I want to know how many process are running with that script. $ ps ax | grep my_script_run | grep -v grep | grep -v "bash -c" 11121 ? S 0:00 ...
-2
votes
2answers
62 views

Find all line in a file which start with g or any digit from 0to9

How do I find all lines in a file which start with g or any digit from 0 to 9? Can any one help me using command line? I try and I know how to do if start with g but don't know how to do with g and 0 ...
1
vote
1answer
29 views

UNIX: excluding patterns, contained in a file, from another file with grep

I have a txt file that contains the patterns I would like to exclude from a file. Is there a way to chain grep -f and grep -v? Thanks
2
votes
1answer
40 views

Why does grep sometimes return directories with two slashes?

I just ran grep -ri foo someDir/ I got back someDir//foo/bar/baz: onDelete() { Does the double forward slash just mean that everything to the left of it was in the dir argument you provided to ...
1
vote
0answers
27 views

Find recursively files that have a percentage of lines in common

Is possible to do this? I want an output where i have only files that are 50% the same of others or have 20+ lines in commons. I'm trying to isolate commons functions in *.java files. Thank you!
0
votes
2answers
35 views

Extract the second quoted string in a line of output

I have a line of output with three quotes, and I specifically need to extract the second quote into a variable. So for example, with the command cmd | grep tokens, I get the following output: Output ...
1
vote
1answer
54 views

uniquely remove unwanted lines in multiple files

I need to remove unnecessary data from multiple output files part of each file looks like this # BLASTN 2.3.0+ # Query: M03117:99:000000000-ALL7G:1:1101:18697:4431_2:N:0:196 # Database: /home/alex/...
11
votes
2answers
851 views

What is less doing with rpm, and how do I get that text without rpm

When I execute less package.rpm, less shows me all sorts of meta info about the package. What is less exactly doing - does it have built in code to be able to extract meta info, or is an rpm ...
3
votes
3answers
52 views

Grep/awk/sed for lines composed of only two letters, and lines that start with a letter and meet a certain length

Not sure how many people are familiar with DNA sequencing data, but if this is part of my file (lines starting with ">" are IDs, and lines starting with a letter are DNA sequences): >NB501013:9:...
2
votes
4answers
56 views

How do i find over 200K differently named files and output

We have a SAN with a lot (over 5 million) of files. Because of some freak mistake from a developer script, some files have been deleted and we now have to figure out which files got deleted. Now, I ...
3
votes
1answer
637 views

Grep that shows the pattern line and the matching line

Suppose I have these two files: 1. Locus_1 univ Locus_2 anc Locus_3 cat 2. university GO:000001 impromptu GO:000002 advanced GO:000003 inheritance GO:000004 I want to do a grep -f of the ...
-1
votes
4answers
40 views

How to show previous line to matching pattern with grep and not the matching line? [duplicate]

I know I can use -A, -B and -C to show surrounding lines but all of them also show the matching line. What I'm trying to make here is so, in this example file: foo bar I'd be doing something like ...
2
votes
1answer
34 views

How can I use sed to snip a line off of a string?

I'm writing a script to display the domain registrar info and I'm trying to snip off a few lines from what I already have I currently have it grabbing all the indented text from a whois. Now I'm ...
0
votes
2answers
36 views

Add time from all log files using bash

I want to extract time from all of my .log files and add all of these times into a single entity. My log files are placed in nested directories. Directory structure for my log files: |-- temp-system ...
0
votes
2answers
10 views

Grep for the closest occurrence of line before pattern

I would like to search the file with GREP for the "User-Agent: UA" and then extract the closest line above that has "Via:" My problem is that sometimes there are multiple lines with "Via:", but I need ...
1
vote
0answers
24 views

filter journalctl output, preserve color [duplicate]

I am using journalctl to watch the system by journalctl -f -p 4, but I'd like to grep-out some information. This works: journalctl -f -p 4|grep -v "maximal mount", but grep discards any color info, a ...
5
votes
2answers
287 views

How can I grep two things where one has option -w?

I have a json file from where I want to get the value of two items which are in an array using grep. Let's say I'm trying to get data from values foo and bar, the problem is that baralso matches ...
2
votes
2answers
66 views

grep for single quote and double quote in a string

I am trying to write a grep which finds the .epl file names or file paths in a given file. I have tried the following regexs Part 1 : REGEX Used grep -rEco "/(.+).epl|(.+).epl" ./index.epl Result ...