Tagged Questions

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

learn more… | top users | synonyms

0
votes
0answers
30 views

How to prevent grep from excessive unnecessary memory usage

I'm greping a hexadecimal pattern (currently a number) from a large binary file (1 TB) with xxd -p /path/to/sda.img | tr -d '\n' | grep -ob '117a0cb17ada1002' and I'm wondering why grep uses up to ...
2
votes
1answer
33 views

Extend grep to find a match after the first match

I have a long list of strings separated by newlines and each section separated by a string starting with ~ (there are no other ~ in the file). I want to extend grep to find the ~ text right below the ...
0
votes
1answer
52 views

Grep -m 1 doesn't work

I'm using the following command to parse a form element from HTML using grep. The $RESP variable contains the output from a previous curl request ... echo $RESP | grep -m 1 -o -E 'name="id" ...
1
vote
3answers
42 views

How to sort the filenames shown in grep command based on timestamp?

In the following command, how can I get the file names based on its timestamp $ grep "exit 0" a* a1.txt:+ exit 0 a2.txt:+ exit 0 a3.txt:+ exit 0 a4.txt:+ exit 0 a5.txt:+ exit 0 $ ls -latr ...
0
votes
2answers
51 views

double grep on tail -f gives no output

If I follow a file somehow like this: tail -f /var/log/syslog|grep s I see all lines containing an "s" Why does this not give any output, if I grep it again to the same "s"? tail -f ...
1
vote
4answers
35 views

How to do grep even if the file is not present?

I am doing something like this in my code file_nm=`ls -latr *abc*` if [ `grep "search_txt" "$file_nm" | wc -l` -gt 0 ] then echo "string found" else echo "string not found" fi If the file_nm is ...
1
vote
1answer
46 views

How to grep the logs for a list of patterns and make a report out of it?

I have a C++ executable which scan some of my files and those files has some user id in it. After scanning is completed it generates below log file (abc.log) like this - INFO [0x7faff2b32a00] ...
-1
votes
3answers
44 views

Find files less than 1 week old with match TODO in files

My unsuccessful proposal find ./ -newerct '1 week ago' -print | grep TODO No output although should be. Files are text files like Lorem % TODO check this out Lorem ipsun How can you find less ...
0
votes
1answer
47 views

grep: input file 'X' is also the output

I use ubuntu 14.4, and attempt to redirect the output of grep command to a file, but I keep getting this error: grep: input file 'X' is also the output I've searched for this issue and just found ...
1
vote
1answer
27 views

tcpdump won't capture entire packet

I'm using sudo tcpdump -A -s0 -ien0 port 80 | grep schemas-microsoft >> ~/Downloads/convert.txt to capture microsoft-schema xmls being sent throught the internet, when tcpdump is supposed to ...
0
votes
1answer
28 views

Manipulate lynx --dump output to get only specific sections

I'm trying to write a unit that will get me a word's definition from wordnik.com from CLI. Currently my code is: function wordnik { (( $+commands[lynx] )) || return 1 ...
2
votes
3answers
101 views

Using grep/awk/sed to sort and combine 2 files

Ok I am running into a problem. I am taking a wifi log that has MAC addresses listed in it. I want to find out what MAC vendors/manufactors for the devices that are connected to my router. I have 2 ...
2
votes
2answers
237 views

How can I grep a certain text and display its line and the line after as well

I have a file similar to: abcdef 123 ghiflk 234 sfhskdhf 483 I would like to search for a string, and the output should include the next (and/or previous) line as well. So for example: grep "bcd" ...
3
votes
1answer
97 views

What is the purpose of those special characters in the sed command?

I found this bash command that creates a directory tree in your console window. I find it quite useful, but I don't really understand how all of the special characters work. Could someone help break ...
2
votes
4answers
56 views

How do i Reverse output already piped from sort and cut commands

I have to take user input of there UID then use it to reference the /etc/passwd directory and sort the data by first name and display only username,firstname,lastname in that order. The problem i'm ...
1
vote
1answer
42 views

Linux log file structure change for usage with kst

My file (tcp dump from networked sensors) has this shape: 20:06:57.049686 IP (tos 0x0, ttl 64, id 26871, offset 0, flags [DF], proto UDP (17), length 68) e108-193.eduroam.tugraz.ac.at.34225 > ...
1
vote
0answers
21 views

grep not matching patterns in scripted session [closed]

We have a bunch of reports that run on a Linux server and I am trying to automate checking them and bringing back relevant parts using Powershell. I'm using a module called SSH-Sessions to connect to ...
1
vote
0answers
24 views

Command that can find files that are not referenced by other files and then delete them

I was wondering if anyone knew how I could go about writing a grep command that recursively finds files that are not being referenced/used in a specific file and/or a directory of files, and then ...
3
votes
2answers
276 views

grep on a variable

Lets say I have a variable line="This is where we select from a table." now I want to grep how many times does select occur in the sentence. grep -ci "select" $line I tried that, but it did not ...
2
votes
2answers
69 views

Limit grep context to N characters on line

I have to grep through some JSON files in which the line lengths exceed a few thousand characters. How can I limit grep to display context up to N characters to the left and right of the match? Any ...
3
votes
1answer
143 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
30 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
30 views

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

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
219 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
32 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
73 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
181 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
22 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
231 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
31 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
30 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
46 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
66 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
50 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
42 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
133 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
41 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
50 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
57 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
65 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
58 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
80 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
65 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
96 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
26 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
65 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
72 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
121 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 ...