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

learn more… | top users | synonyms

3
votes
1answer
126 views

grep not working in a for loop over a list

I have some log files. And I have a list of user ids. My log files are in a particular format log-yyyy-mm-dd e.g. log-2014-09-30 I am trying to search each userId in the log file. This is what I am ...
1
vote
1answer
25 views

grep *gcc* doesn't match anything

I'm using the following code $ rpm -qa | grep -i gcc libgcc-4.8.3-7.fc20.i686 gcc-c++-4.8.3-7.fc20.x86_64 gcc-4.8.3-7.fc20.x86_64 libgcc-4.8.3-7.fc20.x86_64 $ rpm -qa | grep -i *gcc* $ I would ...
1
vote
0answers
25 views

In adb logcat | grep, how to get the entire original line? [on hold]

I am using grep on the Android Logcat to only watch the lines related to my application. My command line is like: adb logcat | grep 'MyAppName' But the results I get is not the original logcat ...
5
votes
4answers
187 views

Replace a string containing newline characters

With the bash shell, in a file with rows like the following ones first "line" <second>line and so on I would like to replace one or more occurrences of "line"\n<second> with other ...
2
votes
2answers
30 views

grep command to display only the two words searched for separated by a comma?

Say I have a file with the following text: Hello there, How are you? How can I grep for Hello and are such that the output of grep looks like: Hello,are
1
vote
2answers
60 views

Print a line in stdout that matches an expression if the output contains another expression

This might be a common/easy task but I couldn't figure out from examples on the web or manuals of awk/sed/grep. So, here is the scenario: There is an internal command line tool that prints out a ...
3
votes
3answers
174 views

Looking to grep or egrep year ranges from 1965-1996

I have a grep that works for some of the dates but having trouble getting my brain to make it fully functional. grep 19[6-9][5-6]$ filename it catches a few correctly but I'm looking to grab ...
1
vote
3answers
20 views

Script to search for 3 different users online and print that

I am attempting to create a script where a user can enter 3 different arguments (usernames) to see if they are online. I currently have who | grep "^$1" which will bring up whoever is searched then ...
7
votes
3answers
229 views

Empty a file without grep subsequently treating it like a binary file

Currently I have netcat piping output to tee which is writing to output.txt with nc -l -k -p 9100 | tee output.txt I want to monitor this output, so I'm watching it with tail -f | egrep -i 'regex' ...
0
votes
0answers
29 views

BC returns syntax error

#!/bin/bash cd ~/simplesim-3.0/benchmarks INSTS=$(grep "sim_num_insn" ./anagram.txt | awk '{print $2}'); IL1_ACCESSES=$(grep "il1.accesses" ./anagram.txt | awk '{print $2}'); IL1_MISSRATE=$(grep ...
2
votes
1answer
26 views

Quotes in commands - grep example

I wanted to know when to use quotes with grep or other tools. For instance the following two command give the same results. [Jhm@localhost /]$ grep Hello ./testfile Hello world [Jhm@localhost /]$ ...
1
vote
1answer
44 views

Understanding grep and pipes in linux

I came across this post which explains my problem. Suppose there is a file called file.txt which contains "foo World". The answer posted by Tyler explains a lot however I am confused as to how cat ...
1
vote
2answers
59 views

How to do a grep on remote machine and print out the line which contains those words?

I have few logs files in my machineB under this directory /opt/ptd/Logs/ as shown below - My logs files are pretty big. david@machineB:/opt/ptd/Logs$ ls -lt -rw-r--r-- 1 david david 49651720 Oct 11 ...
3
votes
2answers
46 views

ack/grep search and sort by modification date

Is there any way to have ack sort the results found by date of modification? (ideally showing the date next to the result?). It doesn't look like ack has a date option, but just in case. If this ...
0
votes
2answers
37 views

Regex to grep filler followed by signed float

I want to extract the last column from lines that look like: 880.952 NAV_Y uSimMarine -146.17516 The number isn't always negative, and isn't a fixed length (i.e. doesn't ...
1
vote
3answers
129 views

keep only certain part of a string in a certain column

I have a file like this: id target_id length eff_length 1 intron_FBgn0000721:20_FBgn0000721:18 1136 243.944268 1 intron_FBgn0000721:19_FBgn0000721:18 1122 ...
0
votes
3answers
46 views

Filter names from textfile

I have a file where there are names sitting in the first character position. I am trying to find a way to grep all the names. Example here I would want the names BUBBA and SUSAN listed. BUBBA = ...
1
vote
2answers
40 views

Strings not outputting text found using grep

I am looking for certain strings in (Windows) executable files. First I started with grep -a string file as that treats binary files like text files. The problem there is there is no neat output, ...
1
vote
1answer
46 views

Regex works in shell but not through Perl script

I'm having trouble executing a Perl script through the Unix shell using Perl's system command. I've had more complex regex commands I had to adjust accordingly to convert from Unix to Perl, and ...
1
vote
2answers
56 views

How to match a number in one file to a name in another file?

Okay, I hope this is the right place to ask. I have 2 files. The first file has 4 fields: class CRN #, Instructor ID #, Class Section #, Number of Students. Example: 0002 T00005 006 15 0004 ...
4
votes
2answers
52 views

How to exchange words in a filename using the shell?

One of my customers is a school. On their file server all projects have a directory with the same naming scheme. <last name>, <first name> <second name>? - <project ...
0
votes
4answers
62 views

grep for files and open the resultant matches

I'm trying to open all files based on some return values from grep in the command line. I know that I can use the -l option to only return filenames, but I would like to combine this somehow with ...
3
votes
1answer
54 views

GNU Parallel - grepping n lines for m regular expressions

The GNU parallel grepping n lines for m regular expressions example states the following: If the CPU is the limiting factor parallelization should be done on the regexps: cat regexp.txt | ...
1
vote
2answers
79 views

grepping for multiple items

I have about 6 items I need extracted from and LDAP base dump file fullName: uid: email: ... the colon is required for the search, mainly because uid appears in a number of places in the file but ...
1
vote
1answer
57 views

Exclude hidden subdirectories from grep -r

I have a svn local copy, i want to make a search on the string some_string. $ grep some_string * -r lang/en:some_string=Some string lang/.svn/en:some_string=Some string But if a go little further, ...
2
votes
1answer
92 views

grep search expression and rename file

I have readable pdf files that all contain the string VAX followed by eight numbers, like VAX00002885. Now I want to find that expression and rename the corresponding pdf to VAX00002885.pdf (in this ...
0
votes
3answers
18 views

How to make a grep which excludes a bunch of pipes?

I want to make a diff of hostnames using grep. I have 2 files. One yaml and one .pp. In the yaml I have domain names with ips and in the .pp file I have fqdn and ip in hash style. Like this: In the ...
2
votes
2answers
57 views

How to get grep exit code but print all lines?

I'd like to check whether a line printed by a command contains an error message, but I'd like to also print all the output from the command (for make logs). Is there some way to get all the output of ...
0
votes
1answer
69 views

Very basic H/W question using pipe and grep

I have two text files, F1a.txt and F1b.txt, with essentially the same data: the driver's surname and their nationality. For example: Hamilton GBR Alonso SPA I have concatenated these ...
0
votes
1answer
120 views

Using Grep Colour to look in a file, and output with a coloured answer in amongst the file contents

I am currently in the process of writing a program in raspberry pi that will allow me to look inside files and have what I entered displayed in colour I think I need to do something to do with ...
0
votes
5answers
45 views

df -k + how to match the root volume line

please advise how to match the "/" volume from df -k command? I tried the following: [root@machine /]# df -k | grep "/" /dev/vx/dsk/bootdg/rootvol 130926685 71378710 58238709 56% / /devices ...
1
vote
2answers
53 views

run grep cmd recursively and print path name and result

I have a log file that exists in multiple directories one for each client. I am trying to run the following: find . -iname "20140926.log" -exec cat {} \; | grep 123456 | grep 'food="100"' | wc -l ...
0
votes
1answer
50 views

Finding words with one vowel group

I am trying to use a command to find all words in a list of words with one group vowels. Like four, for and far, but also words like ore and or. What I got so far: grep -i ...
2
votes
2answers
62 views

redirect output of tee and grep for multiple logfiles

Redirecting output from a script STDOUT + STDERR toLogfile 1 and a grep to Logfile 2 ./run_test.sh 2>&1 | tee -a /var/log/log1.log | (grep 'START|END') > /var/log/myscripts.log How can I ...
1
vote
3answers
188 views

“grep” the available space from “df” output

Hello I need to grep the output from df. Sadly awk is not an option (even though its the easy option) here I can only use grep. Filesystem 1K-blocks Used Available Use% Mounted on none ...
2
votes
4answers
142 views

Remove all comments from a file?

I have a file with a few lines commented out: foo bar stuff #Do not show this... morestuff evenmorestuff#Or this I just want to print all the uncommented code: foo bar stuff morestuff ...
2
votes
0answers
43 views

Using grep to locate string from a text file [closed]

I need to use it to so the program asks the user for the text file and then the string located in that file. Then the program will tell the user whether the string exists in the file.
-1
votes
1answer
59 views

Match and combine records in Bash [duplicate]

Consider two csv files: $ cat given.csv 123,John 246,Paul 369,George 987,Ringo $ cat family.csv 246,McCartney 123,Lennon 987,Starr 369,Harrison Note that the lines are not ordered! How might I use ...
5
votes
3answers
135 views

I am trying to find a better/easier way to count alphabetic characters in a file or shell variable

I have a file containing the following text: we are going to write something 1 2 3 wc tells me I have 1 line 9 words and 38 characters. I'm looking to count the 26 letters only (a-z, no numbers or ...
2
votes
2answers
34 views

Gather job usage information on cluster

I am running simulations on a linux cluster shared by hundreds of other users. There is a job scheduler installed on the cluster that determines who runs where, and one of the scheduler commands ...
2
votes
2answers
79 views

Find characters in the file

I need to find lines in the text file that have at least one x and at least two ys. I tried the following: grep -E "x.*y{2}" file.txt This method did not work. Is there another way to do it?
2
votes
2answers
49 views

Run grep or other commands on files on a web server

I have files on another domain. What's the best way to use commands on them like grep? wget http://path/to/file.txt | grep search However this doesn't work. I guess I can use curl but is there a ...
2
votes
3answers
173 views

grep to find words with all vowels

Using grep -E and regular expressions I need to find words containing all of a group of characters in no particular order. For instance a word containing all vowels (aeiou) however the vowels can ...
-1
votes
1answer
81 views

How to use grep to filter out lines starting with any of a set of keywords?

I have a large file (a chemical database), and I need to display only header records, which are defined as lines that don't start with: ATOM, CONNECT, HETATM, TER, or END. I'm supposed to use grep to ...
1
vote
1answer
42 views

Find files in multiple directories taken from list in a file?

FreeBSD 9.2 RELEASE p2 I have a file dirs.txt. In this file is a new line separated directory list like so: /etc /home /home/goods/ I need to first find in all directory's files which have names ...
3
votes
2answers
84 views

Extract csv files from path to multiple files in bash

I have a files multiple file path for backup purpose ,now i want to filter it based on ".csv " fromat. I have tried this. filesall=(/home/abc/allfiles/*) files=$((${filesall[@]}|grep -F ".csv")) ...
1
vote
1answer
48 views

Store output from one command and process it for another

I am working on Unix command line. I have two files. I want to cat file1.txt and grep the output in file2.txt File1.txt 123A 223A 143A 153A 183A 123J 123P File2.txt: 123A (TYU) 223A (RUT) 143A ...
1
vote
4answers
60 views

Parsing complex text file using Unix commands

I have the following text structure which I would like to parse: >Cluster 423 0 56aa, >HWI-ST1448:257:C3V2HACXX:1:1106:19087:2550.1... at 92.86% 1 64aa, ...
3
votes
4answers
190 views

Test if command accepts a specific option

What is the preferred way to test if a command takes an option? What are the caveats? As a motivating example, at login my shell aliases grep to add several --exclude-dir options but this option is ...
2
votes
2answers
59 views

Use awk to find first occurrence

I have a log file that gets updated when my script runs. The script will insert "Start of script" text when it starts and "End of script" text when it finishes running. I am trying to capture the ...