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

learn more… | top users | synonyms

3
votes
1answer
29 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 ...
8
votes
5answers
673 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
71 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?
8
votes
4answers
658 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
57 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
88 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
18 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
24 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
54 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
68 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
31 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
404 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
42 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
368 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
51 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
289 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
86 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
44 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
75 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
35 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
64 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
37 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
75 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
89 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
65 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
32 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
28 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/...
12
votes
2answers
864 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
53 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
59 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 ...
4
votes
1answer
976 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
41 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
36 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
40 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
17 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
289 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
91 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 ...
0
votes
2answers
55 views

Extracting a date from a log file and creating a file with unique dates

I would like to extract from a file the date with format DD.MM.YYYY, date is always in the first place, here an example of the entries 15.04.2016 13:13:30,228 INFO [wComService] [mukumukuko@system/...
0
votes
1answer
28 views

How to return the matched expression of a grep command

I am trying to debug a command that I regular use to search across my file system. I have an external file that contains a list of regular expressions that I want to match against. Example [the real ...
0
votes
3answers
66 views

How to extract logs between the current time and the last 15 minutes

I want to extract the logs between the current time stamp and 15 minutes before and sent an email to the people configured. I developed the below script but it's not working properly; can someone help ...
0
votes
1answer
34 views

Return owner of process given PID

I'm trying to grab the owner of a process from a list, I have the command pidof nmap to get the then ps -u <PID> | grep USER that I'm currently playing around with, but when I run it, it ends ...
0
votes
2answers
80 views

How to process a file containing quotes?

I know a fair bit about escape characters in BASH. I know that \ will escape the next character, " " will escape all characters except for $ and ", and finally ' ' will escape all characters except ...
1
vote
1answer
81 views

Why grep on remote system says file or directory not available

I'm trying to run a grep command on remote system to give me the result for May 22. But reply comes /bin/grep: /var/log/Clients_Logs/127.0.0.1/*: No such file or directory But when I specifically ...
0
votes
3answers
51 views

Command to print the number of *.pdf files in a chosen directory [duplicate]

I am currently not on a Linux machine. Would the following command produce my wanted result? ls | grep ".pdf" | wc
-4
votes
2answers
52 views

recursive script not working

I am trying to add recursive support to my filegrep script. For some reason this does not work as expected: RECURSIVE_MODE=off # iterate over args for ARG in "$@" do if [ -d "$ARG" ] && ...
0
votes
1answer
36 views

have a log file that I would like to break up into several files based on content

I have a log file that I would like to break up into several files Table of Contents *** Configuration Database *** Logs *** Configuration Logs *** Query Logs . . and so on The issue ...