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

learn more… | top users | synonyms

3
votes
1answer
22 views

How can I do a binary search of a text file for a specific character string?

I have a text file that contains a large number of records, each on a single line. Some of the records have special characters that have been corrupted, and I'm attempting to find those by looking for ...
1
vote
1answer
38 views

copying and working on OSX .app files (folders) in linux

tldr; I want to run a script over an external hard drive and tar.gz every folder that ends with .app into their own archive. That is, I don't want them all in one tar.gz file, I want to create one ...
1
vote
1answer
30 views

display users that logged in since a date using last

I am trying to display the user name of the accounts that have logged in during the past month using the last command. At the moment I have this last | awk '{print $1, $4 ,$5 ,$6}' | grep -B 10 Jul ...
1
vote
1answer
66 views

Filter screenlog with screen command

Pressing Ctrl+A, H, lets me log output of the screen command. However, the output file is too large. Is it possible to apply a grep-like filter so that I can control what gets logged? For example, I ...
1
vote
1answer
89 views

tool in terminal like helm-occur/helm-swoop for terminal?

I don't know whether this is the right place to post this question, but if you are not an Emacs user, I'll explain the basic usage of helm-occur/helm-swoop. I like helm-occur/helm-swoop for Emacs ...
0
votes
1answer
13 views

Trouble using if string in column 3 of .csv exist, then statement

I have a set of 10 files. 5 are unique tumors tissues and the other 5 are matching normal tissues… So {tumor_A, normal_A, tumor_B, normal_B,… tumor_E, normal_E} These files each have a random ID, ...
0
votes
1answer
28 views

live tail (tail -f) of file being grepped

i can do tail -f -n20 <file> to see the last 20 lines of the file, live. If i want to grep something, tail -f <file> | grep <pattern>, it will still be live, but will only grep ...
0
votes
1answer
43 views

Fetching logs from log file using grep

I am trying to fetch logs from log file using grep command and format of log file is as follows: [1/10/16 23:55:33:018 PST] 00000057 ServerObj E SECJ0373E: Exception message at ...
0
votes
1answer
26 views

How to recover a node/content from a tarfile that's been overwritten

Disclaimer: I'm not very good at writing questions, and mine is a very specific scenario. So I'm just going to jump straight into the situation: I was browsing my filesystem, and somehow managed to ...
0
votes
1answer
90 views

Grep -v filter not working

I want to filter grep results by using grep -v option. But the output does not differ when using a particular pattern. contents of log.log: ERROR error EXCEPTION exception ...
0
votes
1answer
47 views

Fetch second and fourth column from a file

Problem Statement I am not able to get the values in second and fourth column. Tried grep -i "AUGC\|AACN\|AACY" output.csv | cut -d ',' 2,4 DATA ...
0
votes
1answer
40 views

Print concat vars inside loop

I have a code like this: cat input | while read p; do lynx -dump "www.xyz.com/p?=$p" | grep -m 1 -A 1 "Hello" | awk -F: '{print $2}' >> output done Where the content looks like this: [$p ...
0
votes
1answer
226 views

Grep /var/log/maillog for email to a certain user, based only on his linux username

Level 1, beginner here. Question about grep and maillog. I have a learning environment, based on Linux CentOS, with Postfix and SquirrelMail running, but my assignment is more in general. I need to ...
0
votes
1answer
45 views

Grep unix for a data to find out result

i have a file, contains huge data. for example there is written "COST-> 1.00" line. and i would like to grep for example between 1.00 and 100. it includes both integer and string characters. how ...
0
votes
1answer
97 views

Delete email addresses in .csv that are listed in a .txt file

I run the following command to keep email addresses listed in emails.txt grep -wFf emails.txt file.csv > newfile.csv But how would I change this command to remove addresses from file.csv that ...
0
votes
1answer
85 views

Script for update

I need your help in a script used for update : OLD="int 10" NEW="int 20" i=0 DPATH="/home" for f in $DPATH do sed -i "s/$OLD/$NEW/g" $f let i++ echo "modified:" $f done what i need ...
0
votes
1answer
63 views

Search and replacing strings in a numerical data file

I have a data file I need to edit it is in the form: ...
0
votes
1answer
285 views

Find all the PHP scripts with email in my postfix mail queue

How do I find all the scripts that have mail sitting in my postfix mail queue? This server is sending out spam and I've spot checked it, but I want to make sure I haven't missed any scripts that may ...
0
votes
1answer
135 views

Search a file for a string in multiple directories

Can someone please help me with a command to search a file for a string in multiple directories? I am searching for the VIP in httpd.conf in multiple httpd instances. I am using: find ./ -name ...
0
votes
1answer
120 views

Colorize line number in grep

Is there a way to colorize line numbers when using grep with the -n option? For example, echo "hello" | grep -n lo outputs 1:hello where lo is colorized in red (being the match). Can I configure ...
0
votes
1answer
203 views

Reading a string till a key word and replacing from there with another string

I am new to UNIX and am practising shell scripting. I have an application where I need string searching and replacement. There are some lines in a file 1 and file 2. I have a search key word. If the ...
6
votes
0answers
36 views

agrep with directionally biased penalties

I am using tre-agrep (manpage), an implementation of agrep (manpage), to perform approximate pattern matching. This utility searches for matches based on Levenshtein distance, and the user can ...
3
votes
0answers
50 views

Print some lines before and after pattern match excluding lines matching another patterns

I use awk on Solaris to print 5 lines before and after a pattern match. Currently, the following one-liner does the job: /usr/xpg4/bin/awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print ...
2
votes
0answers
505 views

exit code of grep in trap where the script is launched by upstart service

Recently I encountered a problem in ubuntu upstart and trap in Bash shell. I use ubuntu 12.04. The upstart script(/etc/init/player.conf) is: start on (local-filesystems and runlevel [2345]) stop on ...
1
vote
0answers
29 views

Can I clear an env var during bash completion?

I use bash completion from https://bash-completion.alioth.debian.org/ and some vendor supplied scripts too (eg. https://github.com/git/git/blob/master/contrib/completion/git-completion.bash) I also ...
1
vote
0answers
33 views

How to extract weather data from a html doc using linux string manipulation

I need to extract these info from this weather forecast site, but I don't know how much about string manipulation in linux: acm_RecentLocationsCarousel.push({name:"Irvine, CA", daypart:'day', ...
1
vote
0answers
35 views

Extract coordinates of matching text in PDF

Basically I want to grep a string in a PDF and get the coordinates of the matching result(s). I already use pdftotext to do the opposite, namely to extract some text given its coordinates. In ...
1
vote
0answers
107 views

Find and delete lines containing multiple patterns in a file

I have a list of strings and want to find and delete lines containing these strings in a file. A short example of the list of strings is listed as below. File S 1Mo 32,33 2Mo 7,26 2Mo 7,27 2Mo 7,28 ...
1
vote
0answers
28 views

accessing old data from syslog

I look after various MySQL DB's which we have recently moved to Linux servers (from Windows). They run fine and everything is good. However, this morning i needed to check the error logs, but these ...
1
vote
0answers
97 views

Grep can't find end of line in DOS format text file?

In Ubuntu I'm working on a C file that was originally created under Windows and then committed to source control. Vim shows the file format is "dos", which I gather just means it has CR/LF line ...
1
vote
0answers
164 views

Grepping multiple instances of a string, with context, from a file

I have a MySQL dump file, which is mostly INSERT statements. I want to grep out instances of the string 'media' from a field in a particular table, with +/- ~10 characters of context. The string might ...
1
vote
0answers
38 views

Review GREP and FIND results in Xemacs

I spend a lot of time searching code. I really like grep and find, because of all the options available. But it takes way too long to navigate the results. I use xemacs and it takes 3 more commands ...
1
vote
0answers
107 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 ...
0
votes
0answers
19 views

replace long text string (script with MANY special characters). sed, awk, grep

My site was hacked / infected. I replaced the url of the malicious link, but other elements in the malicious script are still making my site get blocked. Without inserting a hundred or so "escapes", ...
0
votes
0answers
43 views

Unix scripting : Writing to another file with “:” is failing

I have below record (and many other such records) in one file 9460 xyz abc (lmn):1027739543798. Taxpayer's identification number (INN): 123. For all IIB. 2016/02/03 I need to search ...
0
votes
0answers
12 views

How to take lines containing a particular string tag from a text file and add then to another text file?

I have a large text file with some data that I need and a lot of data that I don't need. The data that I need has a string tag at the beginning of the line followed by a numerical value which I need. ...
0
votes
0answers
27 views

Reboot on grep in /sys directory

I just run the following command (on a Android in VirtualBox): grep -Hirn 'VirtualBox' /sys/* and the system rebooted. I wonder why this is the case, any suggestions?
0
votes
0answers
40 views

How do I use grep to search for strings that exist both on single lines and multiple lines?

I am searching large amounts of SQL scripts for data dependencies but due to variations in the scripts, I have encountered an interesting problem. If I am searching for the word FROM it only returns ...
0
votes
0answers
37 views

Finding word with centain length containing characters from interval

I am trying to print all words that are 3 chararcers long and those characters are from [a-s] interval. I have tried following grep '\<[a-s]\{3\}\>' file.txt which outputs nothing , i have ...
0
votes
0answers
32 views

Quoting the pattern in grep and it's still interpreted as an expression?

I have a simple script that I'm using to find CSS definitions in a vanilla bootstrap.css file, then I'm trying to find overridden/duplicate definitions in several other css files where other ...
0
votes
0answers
78 views

Unable to match multiple ip addresses using grep

I am trying to match multiple ip addresses, 100.x..x.x and 13.19.x.x here is my syntax. for item in `cat s3` do egrep -o '100\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} | ...
0
votes
0answers
51 views

Sort Checkpoint Firewall log into easier output

I am trying to sort out this log: Aug 27 01:23:38 1.1.1.1/1.1.1.1/1.1.1.1 fw1-loggrabber[0000]: loc=12569|time=2015-08-27 ...
0
votes
0answers
35 views

How to print line numbers using sgrep

I have a large text file : file_1 about 400 MB I have another text file : file_2 which is 7 MB I need to find the strings of file_2 in file_1 and write their matching line numbers to an output file. ...
0
votes
0answers
39 views

Postgres server start fails - netstat -ant|grep 5432 output explanation?

I'm working on a Ruby on Rails app. Hosting on Heroku with postgres. Tried running "heroku run rake db:migrate" as usual, but getting error "cannot connect,... check if something else is already ...
0
votes
0answers
131 views

How to properly structure a zgrep command to return the proper count of expression matches?

I am trying to search through several bzipped CSV files and return a count of emails that contain a .br domain extension. It seems straight forward enough but I have not been able to structure a ...
0
votes
0answers
29 views

Why does not changing changing LC_ALL from utf to C speed up my grep?

I wanted to try to speed up my already fast grep. I read that changing lc_all from utf to c was supposed to do this. However, it gives no speedup. What might the reasons be? How do I "debug" this? ...
0
votes
0answers
111 views

SED: print entire paragraph for specific pattern while loop

I find partial answer about my problem on this question but i still have trouble. I need to use a variable as a pattern for the sed command in a loop sed -e '/./{H;$!d;}' -e 'x;/'$var'/!d;' The ...
0
votes
0answers
48 views

egrep for specified strings and newline

I receive a prespecified list of strings. In a number of textfiles (example below), I want to search for strings, that do not start with one of the strings in the list. From time to time, a blank link ...
0
votes
0answers
279 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 ...
0
votes
0answers
1k 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 ...