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

learn more… | top users | synonyms

2
votes
1answer
32 views

egrep multiple patterns with dashes

I am trying to match the followings with egrep '201411[08|09|10|11]-[117|111]-' 20141108-111-xyz-abc 20141110-117-342-lala But for some reasons, the 2nd character class pattern ([117|111]) doesn't ...
1
vote
2answers
102 views

Search 2nd line of files and print filenames to stdout

I have a few directories of ~10,000 files. What's the quickest way to search each file and return the filename if the second line contains a specific string? Edited for clarity
1
vote
2answers
67 views

find field pattern in a csv file then count unique field values

I am using Cygwin (bash) to create a script to find, group and count fields in multiple CSV files. Each row will have comma-separated fields with each field following a similar convention. There is a ...
3
votes
3answers
249 views

How can I delete all text between curly brackets in a multiline text file?

Example: This is { the multiline text file } that wants { to be changed } anyway. Should become: This is that wants anyway. I have found some similar threads in the forum, but they don't seem ...
-1
votes
1answer
45 views

Information about grep cammand [closed]

Both two outputs came in my terminal. sda 13.45 479.55 84.92 812139 143808 sda 5.00 4.90 4.00 13 24 I want to get ...
3
votes
1answer
69 views

How to format grep results?

Wow, I could not think of a good way to title this question. Basically I have a file called "attendance" with data like this: 11/06/2014 101.11.001.01 FirstName LastName 11/06/2014 101.11.001.01 ...
1
vote
5answers
77 views

Regular Expression for Mixed cased words

I want a regular expression that will help me identify if a certain pattern is present as a mixed case in a sentence or not. Say: Fox juMPed the rock Now, I want to find that if the pattern ...
2
votes
6answers
89 views

Getting the matched word exactly

I have looked through a number of question but they do not satisfactorily reply to my question. I need to print words that match the pattern exactly not the lines containing that word. For example: ...
4
votes
0answers
106 views

what is grep -v -f /dev/null expected to do exactly?

Theory: grep -f somefile or grep --file=somefile will find all lines that match one of the patterns listed in somefile. If somefile is empty, nothing will match. With grep -v you list lines that do ...
2
votes
1answer
72 views

grep of a shell variable finds nothing

I have some problem with grep. I wrote a script which need to find some numbers from a list (file name ContigsNames) in a database. I wrote the following script: file=ContigsNames while IFS=' ' read ...
2
votes
3answers
48 views

Removing lines from one file based on non-existence in another

I need to remove lines from fileA which has two columns if fileB (one column only) does not contain the string from column1 in fileA. Any linux command would help. Thanks. Example. Here is fileA: a ...
0
votes
1answer
14 views

add fields from different lines in one line

I'm trying to add the .data and .bss sections of the size -A output size -A mylib.so | grep "\.data" | awk '{print $2} this will print the value of the size of the .data section. I guess I could ...
0
votes
3answers
83 views

How do I search a file for a string then use it as a variable?

I have an XML file that looks like this: <id>456</id> <root> <value>1</value> <intNum>2</intNum> </root> <root> <eulav>1</eulav> ...
3
votes
3answers
67 views

How can I base the file name off of an already existing variable?

I'm using this to delete lines that don't match a pattern: $ egrep "pattern1|pattern2|pattern3|pattern4|pattern5" But now I need to do it automatically, so I'm setting a variable like this: $ ...
0
votes
2answers
44 views

Delete consecutive lines if patterns match in each line

Good day, I was wondering how to delete to consecutive lines when this pattern is found: /^pt [a-z]\npy [0-9][0-9][0-9][0-9]\n// Expected Input pt a py 01234 pt b cd abc py 5678 Expected Output ...
2
votes
1answer
54 views

how to use grep -v in an expect script

I'm new to expect scripting, trying to implement below command (that works otherwise) in an expect script $ grep -i cps config.cfg | grep -v "//cps" | grep -v "cps := 4.1" | \ grep -v "cps := ...
0
votes
0answers
45 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
51 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
71 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
86 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 ...
1
vote
2answers
107 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
45 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
73 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
74 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
127 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
49 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
34 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
217 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
255 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
108 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
68 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
48 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
33 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
26 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
319 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
160 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
170 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
35 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
55 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
353 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
50 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
82 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
205 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
26 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
253 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
61 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
57 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
60 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
120 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
131 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 ...