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

learn more… | top users | synonyms

2
votes
2answers
40 views

Autocomplete from grep output

How might I more easily use a filename found by grep as an argument to vim: $ grep -r foo * lib/beatles/john.c lib/pantera/phil.c lib/pinkfloyd/roger.c lib/pinkfloyd/richard.c ...
1
vote
1answer
33 views

grep content between two starting bracket

Below is file output that I want to access [1] RsyncCommand: 0 Number of files: 18 Number of files transferred: 0 Total file size: 24.01M bytes Total transferred file size: 0 bytes Literal data: 0 ...
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. ...
5
votes
6answers
179 views

Take grep value and output the count and the value together

I am trying to make a bash script that greps value and output the count and the value together Something like this grep -c 'Thenis' example.txt > example.lst But in that list file not only to ...
5
votes
1answer
54 views

Behavior of grep -o on OSX

On Linux, when I do echo foo | grep -o '^.' to get the first character, it prints f as expected. (I know, | cut -c1 would probably be faster.) But on OSX, doing the same results in 3 matches (3 ...
4
votes
1answer
156 views

grep of top output yields funny characters upon redirection to file

I am running CentOS 6 and I am trying to grep the output of top and redirect it to a file. I.e. top -u user1 -n 1 | /bin/grep somecommand &> scratch.txt The output of vim scratch.txt is ...
0
votes
2answers
72 views

Parsing HTTP response with shell

I want to parse below HTTP response but I cannot figure out how to grep the values separately using a single curl request. I need these two output. 1. status_code - (Array of HTTP status codes) 2. ...
1
vote
3answers
59 views

grep a awk string from a file and write to the other part of string file

My file, aaa,has 5 lines. 01_AAA-11-ID22 02_BBB-33-ID44 03_CCC-55-ID66 . . I tried to grep anything after underline from a file bigfile.txt for i in $(cat aaa) do A= $(awk -F '_' '{print $1}' $i) ...
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 ...
-1
votes
1answer
26 views

cut command behaving differently when its output is “ * ” [duplicate]

I am trying to create a shell script, below is a part of which where i am trying to extract some value from a record in a file: tgt_val=`cat $file_name | grep "$string_name" | cut -d"|" -f$column_no` ...
2
votes
2answers
61 views

Selective extraction of data

I have the following block of data in a txt file : Informatica(r) PMCMD, version [9.5.1 HotFix4], build [313.0217], SOLARIS 64-bit Copyright (c) Informatica Corporation 1994 - 2014 All Rights ...
0
votes
1answer
61 views

Using sed instead of grep to output only matching part of line

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in ...
10
votes
3answers
284 views

How to extend bash aliases

How to create an alias that actually extends another alias of the same name in Bash? Why: I used to have GREP_OPTIONS set on .bashrc to something like this: GREP_OPTIONS="-I --exclude=\*~" I also ...
3
votes
1answer
47 views

Colored Output from Bash Script

I'm running grep inside a bash script. If I run the grep command directly, I see colored output of the file name and search string: grep -i username /tmp/sess_* If I put that command in a bash ...
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?
1
vote
2answers
71 views

Complex sed Command with AND/OR/NOT

I have a bunch of php files which have many select commands. In each query i want to insert a coloumn variable admin_id = '$admin_id' i.e. if the query is select * from users where abc='xyz' and ...
1
vote
3answers
109 views

regex matching and substring extraction

I have these files, manually created by many different people are coming in. Formatting, although following a certain rule, is not uniform. think of these three lines below ...
0
votes
1answer
26 views

Pattern highlighting command [duplicate]

Folks, I want to know if there exists a command that just highlight some portions of the input text, rather than filtering it like grep does. To give an example, suppose the following input text: ...
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
3answers
47 views

remove files based upon diff of two text files

I have created two .txt files that look like: 5fba026dcf271c6fa174b9fc2fc1fefadf1370f9 ./.changeFiles/change/addImage1.change bb352fba5807f4d03ea11abb00e411b00ce38673 ...
1
vote
2answers
35 views

Return line conditonally on next line

I am trying to return a list of IP Addresses for computers that have a windows OS (for my security course). The output is in this format Nmap scan report for 192.168.xx.xxx Host is up (0.066s ...
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
4answers
68 views

How to show only hidden directories, and then find hidden files seperately

I'm trying to list all the hidden files in a directory, but not other directories, and I am trying to do this using only ls and grep ls -a | egrep "^\." This is what I have so far, but the problem ...
1
vote
4answers
50 views

bash extract a substring from “1.2.3-SNAPSHOT”

How can I substring a 1.2.3 from a 1.2.3-SNAPSHOT from bash? I tried echo '1.2.3-SNAPSHOT' | grep -o "^.*(?=(\-SNAPSHOT$))" but it didn't work Ideally I'd like a command to return 1.2.3 in both ...
1
vote
1answer
106 views

grep -f failing on a file edited in Windows

I just want to share a problem I had this morning using grep -f to obtain the patterns to match from a text file. Symptom $ echo 'sandbox/test/script.py' | grep -G '^sandbox/' sandbox/test/script.py ...
1
vote
2answers
40 views

Prefix and suffix strings to each output line from command

I have ran into a problem trying to write a Bash script. When grep outputs, it returns (usually) many lines. I would like to prefix and suffix a string to each of these output lines. I would also ...
2
votes
5answers
139 views

How to make grep return value without comma [duplicate]

I want to extract a value from a json file so that I can process it and I try that using grep '"USDEUR" currs.json' | cut -d ':' -f 2 but it returns 0.918695, and the json file looks like this: { ...
1
vote
1answer
40 views

Unix awk decimal export in pipe

I'm struggling to adapt a script, which loops through a large number of individual files (subj_id), and prints out the value of $4 in a specified line. Text file contains lines # Measure Brain, ICV, ...
4
votes
2answers
52 views

Invert matching lines, NUL-separated

I’m writing something that deals with file matches, and I need an inversion operation. I have a list of files (e.g. from find . -type f -print0 | sort -z >lst), and a list of matches (e.g. from ...
5
votes
2answers
37 views

Scrabble helper in bash

I'm trying to make a scrabble helper in bash, which when given a list of characters, finds all the words in the /usr/share/dict/words file. For example, when given the letters a,c,r,t The word cart ...
0
votes
2answers
38 views

Parameter expansion in grep

To retrieve strings of the following pattern from a text file populated with multiple entries: entry=G_1234 entry=G_5678 entry=G_2345 The following grep statement doesn't provide any result grep ...
0
votes
3answers
52 views

sudo iwlist wlan0 scan | grep ESSID > essid.txt (How do I export without the word ESSID in txt file)

So my goal is to answer my other question I am working on. Which is Connect to Open Wifi. Currently I am getting close, as I know there is only one Wifi connection, I would like to export the results ...
5
votes
3answers
240 views

egrep regular expression - same word in the beginning and end

I want to find all the lines that have the same word in the beginning and in the end of the line. For example: goodword fgdlakj 3t sfkl 43lk fkl goodword bad sfa;lk3t dgk;gs 34;kl ...
1
vote
3answers
36 views

script not running as expected when scheduled as a cronjob

I'm trying to write a script that will identify corrupt jpg images using imagemagicks identify command. The script will run the command, grep the output for the word "Corrupt", move it to a corrupt ...
0
votes
4answers
71 views

Why isnt this simple grep/sed script working [closed]

I have a variable with, among others, a line that looks like this iBMC=277 I'm trying to match that like this: BMC="$(echo "$allnow" | grep iBMC=[0-9] | sed 's/iBMC=//g')" This makes BMC empty. ...
1
vote
1answer
18 views

How do I get grep to search for ebuilds with specific strings and produce an output containing only the ebuild's location?

I have been trying to create a Bash script function that can be used to search for and open ebuilds with desired strings in Atom (the text editor). This is my current Bash script function (stored in ...
2
votes
3answers
48 views

How to extract particular field from rows from a file, based on matching subsequent rows

I am trying to replicate a workplace problem. I have a xml file like below [~]$ less -N sample.xml 1 <SOURCE BUSINESSNAME ="" NAME ="TABLE1" FOO="ABCD"..... > 2 <SOURCEFIELD ...
14
votes
1answer
713 views

How to “grep” for line length *not* in a given range?

NOTE: This question is the complement of this Q&A: How to "grep" for line length in a given range? How can we grep for lines that have less than 8 or more than 63 characters, none ...
1
vote
1answer
41 views

How do I grep two patterns from one file and direct the lines to different output files depending on which patter matches?

I'm searching for two patterns from very large files and I don't want to grep more than once. I'm currently running this command to look for the patter, then if found also take the one line before ...
3
votes
2answers
43 views

How to use grep to return lines with an hexadecimal number in a given range?

If I have, say: blah;PC=1234abcd PC=4444bbcd;blah PC=0000abcd;;foo PC=1234abff How do I grep for lines with PC values in a given range, say 1234ab00 to 1234b0ff. The - range option seems to only ...
5
votes
2answers
408 views

Find files containing string in file name and different string within file?

I would like to (recursively) find all files with "ABC" in their file name, which also contain "XYZ" in the file. I tried: find . -name "*ABC*" | grep -R 'XYZ' but its not giving the correct ...
2
votes
2answers
39 views

How to view all ancestor processes?

How can I view all the ancestors for all instances of a given process name?
3
votes
1answer
63 views

grep two conditions, one negated, without a pipeline?

Assume we have the following test.txt: # commented line, no match # commented line, would match /app/ # again commented, would match app non commented line, matchin /app non commented line, no match ...
3
votes
3answers
78 views

Print all matching lines and the previous unindented line

For example, lets say I want to find all lines with 'matching' and the previous unindented lines in this text. Container 1 some text some text matching text some text Container 2 some ...
7
votes
5answers
1k views

How to find lines containing more than 100 characters and contains “if”?

So, probably I should use grep for this. As long as I need recursive search I should use grep -r. But then I don't know what should I do next ;) How can I do that?
2
votes
2answers
40 views

Use of \$ at end of variable name passed to grep

I was going through one of the shell scripts and found a line : ls $dir | grep -c "$NAME.${var}\$" I understand that $ would expand the variables NAME and var, but is it required to put \$ at the end? ...
0
votes
1answer
25 views

what grep -oh “[*?<com]” do?

I am trying to achieve something and in the experiment I came through following case , could somebody explain me how to understand whats happening. echo " Agent process not running on ...
0
votes
2answers
46 views

how to parse hostname from a line

I have a line : Check space in www.raja.server.local.com and it is 40% full in /usr I want to just parse www.raja.server.local.com from above line. Note: www.raja.server.local.com can be any ...
0
votes
0answers
39 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 ...
2
votes
1answer
168 views

GREP exclude first 11 values

I have a massive log file that I need to filter. In this log, I want to display all logs that contain the string dns and I want see them just once. i.e from this: Dec 9 07:24:02 94.15.218.140 ...