0
votes
3answers
43 views

Grep for block surrounding an error message

I want to grep for the block of logs around a particular error message. Say I know my log looks like this: [----] I, [2014-04-10T19:12:36.294512 #1910:e93004] INFO -- : Started GET "/ems_infra/new" ...
1
vote
2answers
39 views

Why doesn't grep work with single quotes?

I have a bash script wrapped in " " so I need to use ' ' for my grep command but it doesn't work. I can't switch the quotes because then the variables are not expanded. #!/bin/bash PWD=`pwd` source ...
3
votes
1answer
51 views

Using grep to filter output of a process

I'm using command | grep -v "JavaScript strict warning" to filter the output of a command (hiding warnings). The grep command works fine when I test it like this: $ printf "JavaScript strict warning: ...
1
vote
1answer
64 views

How to redirect ALL output from a command in Linux

I'm running Gentoo Linux. A program (equery) outputs a massive list of all the currently installed packages (equery list "*"). I want to find out which of them are unstable. Equery marks the unstable ...
1
vote
2answers
49 views

Tail and grep recursively?

Trying to tail though a list of domains to search for a hacker code. All the files that I'm looking for are the same so I was trying something like this: grep -rnl * -e "Ai9LbaFz7lC13SwzDxAYT72vwA" ...
1
vote
2answers
48 views

Is there a way to print 2 lines (if any) before and after a target or print a placeholder if not?

I'm not native english speaker so I hope to be clear. I know about grep -C 2 "TARGET" inputfile to select 2 rows before and after the row of the TARGET, but I'm not able to use it to manage my ...
1
vote
1answer
51 views

How do I pipe output to date -d “value”?

I have a date like "2014-01-30 05:04:27 GMT", and if I run date -d "2014-01-30 05:04:27 GMT", the output is in my server's timezone ("Thu Jan 30 16:04:27 EST 2014"). With the use of grep and cut, I ...
0
votes
3answers
108 views

Bash - Move those files that contain the string to directory

Task: Create script, that will take 2 arguments: 3.sh <directory> <destination> Search the files in <directory> for substring “moveme” in the file content Move those files that ...
1
vote
4answers
75 views

String Search: find and grep and?

Task: 1) find a string 'decor' inside files in a directory 2) get # of occurrence for decor for each file that has it The first part of the problem is partially solved with find . -type f | grep -i ...
1
vote
1answer
37 views

Why can ps know about the process that runs after it?

[root@myvm1 ~]# ps aux | grep ls root 13594 0.0 0.1 3912 672 pts/1 R+ 09:46 0:00 grep ls In the above, the ps aux runs first and its output is then redirected to the grep ls ...
0
votes
1answer
649 views

Recursive zgrep not working

I have a directory hierarchy that contains numerous .gz files. I want to be able to recursively grep them for the string "foo". From what I've read online the following should work: zgrep -R -H ...
2
votes
2answers
295 views

How to grep a group of files within a time range?

I'm trying to write a script used on a buffer box that does full packet capture of network traffic. As it's for a fairly big network we split the captures into 100MB segments. At times of high network ...
0
votes
1answer
40 views

How to zsh pipe to grep to match remote branches beginning with 'orgin/'

I tried this: git branch -r --merged | grep '^origin/' But I get nothing... When I remove the caret: ✗ git branch -r --merged | grep 'origin/' origin/HEAD -> origin/master ...
0
votes
0answers
50 views

Linux flow control exit or break on condition

I have a query about the following flow control. I need help to run a script that has these three conditions: Conditions: Successful: Proceed to read message. Fails: Exit to cat or just exit ...
1
vote
2answers
57 views

How to save linux command?

I am using grep -r [^a-zA-Z0-9]myVariableName[^a-zA-Z0-9] -n JS_files/ as mygrep file grep -r [^a-zA-Z0-9]$1[^a-zA-Z0-9] -n JS_files/ and then sh mygrep myVariableName But then I lose the ...
2
votes
1answer
478 views

Filter tail command through multiple grep commands to separate files

What I am trying to do is filter the output of one log file into separated log files based on a grep filter. tail -f test.log | tee >(grep "Error" > error.log) >(grep "Warning"" > warning.log) ...
0
votes
3answers
119 views

Write pipe result to variable

I need to be able to write whether the test for a grep is either TRUE or FALSE to a variable so I can use it later For the following, if I run defaults read com.apple.Finder | grep ...
3
votes
2answers
63 views

Sort files with grep

I have a few hundreds of output files, of which some contain error messages. Lets say I want to automatically put all files containing the string "ERROR_1" in a "subfolder_1", and the rest in a second ...
2
votes
3answers
116 views

What does really mean null string?

I'm sure most of us know that when we want that some regex matches with a string at the begin of the line we must use "^" ... But, I'm trying to understand what really means "empty string at the ...
0
votes
2answers
158 views

Writing a single line command that interprets conditional output from pdbedit

I would like to run a command on a single line that will tell me if the flag is set for a user's password to be changed on next login. This command will interpret the output and return a true/false. ...
3
votes
1answer
2k views

How can I avoid the “grep: Argument list too long” error?

I'm using Mac 10.7.5 and on a bash shell. I'm trying to find instances of a string in a group of files but keep getting this error Daves-MacBook-Pro:folder davea$ find . -name "*" | xargs grep ...
0
votes
1answer
879 views

Save result of a grep -c into a shell variable

How can I store the result of grep -c as an integer in a shell variable? This: check=sudo virsh list |egrep -c '\b[0-9]{2}\b' only gives me the number of matches and prints it on screen whereas ...
21
votes
3answers
645 views

How to prevent a password or other sensitive information from being stored in the bash history when using grep?

I had to grep recently for a password that may have been saved in a file. I did not want that line to show up in the bash history. How can I prevent a password or other sensitive information from ...
0
votes
1answer
118 views

Grep get everything except matching

Lets say I have a text file that says: Hello my name is agz. I am asking a question that is important. If i type: grep -v "is" /path/to/file, I should get no output because both lines have "is". ...
3
votes
2answers
800 views

Efficient way to search string within file find and grep

I am searching all files containing a specific string on a filer (on an old HP-UX workstation). I do not know where the files are located in the file system (there are many directories, with hudge ...
0
votes
1answer
442 views

Using Mac OS X terminal to copy a selection of folders to a new location, with merge behavior

I have a folder 'foo' that contains a lot of sub folders, e.g. foo |---20101 |---20102 |---20103 |---20111 |---20112 |---20113 There are way more than this, but hopefully it explains the ...
2
votes
3answers
257 views

How to use grep to search for regular expressions themselves, without parsing them

grep . filename.txt This just returns all of the contents in filename.txt, because . is a regular expression that stands for any character. How do I use grep to search for periods, or other regular ...
3
votes
1answer
2k views

Using grep to remove lines from a file which contain a string from another file

I have a file containing words (one per line) such as Dog Fish Cat Shoes I have a secondary file in CSV format such as 1,shoes,red 2,apple,black 3,fog,blue I would like to use grep with ...
1
vote
1answer
235 views

grep with colored output returns several empty lines

I have strange issue with grep (2.12-2, debian testing). In some situations when I do something like this: grep -rni '."spacer">.' . grep return me several empty lines: If I add --color=none ...
1
vote
1answer
318 views

How to Grep up to a certain character or String

I need to extract log data from many terrabytes worth of log files. The thing is, the data I need starts and ends with patterns I can identify, but the code between can be anything between 10 and 100+ ...
0
votes
3answers
105 views

Grep for This and NOT That in a File?

How can I grep for files in a directory structure that have this text addDesignControlChangeNotification but are missing this text removeDesignControlChangeNotification Thanks! Note: I mean the ...
0
votes
4answers
1k views

How to combine find and grep to recursively search for str or str2 in *.html and *.php files from /home/smith/sourcecode?

How can i combine find and grep to search for str1 or str2, recursively, in all *.html and *.php files starting from a directory named /home/smith/source? The output only needs to list files (with ...
1
vote
3answers
794 views

How to grep long string across multiple lines, without knowing where the newline is

I want to search for a specific string across multiple lines in a file and get the line in which the match was found. However, my problem is, that the file contains one very long string, and not, ...
1
vote
2answers
81 views

Finding folders only

My harddrive is in a mess, so I decided to do a cleanup. As a part of this, I want to merge all folders containing music into one. What I want to do is, look for any *.mp3's and *.aac's on my drive ...
1
vote
1answer
243 views

How to ack-grep replace a string of multiple words

The following command replaces every occurence of the word from in any file of the current directory or its subdirectories with to: ack-grep -l --print0 --text from | xargs -0 -n 1 sed -i -e ...
5
votes
3answers
179 views

Can bash consume the same fifo from two separate commands?

I have a huge data source that I'm filtering using some greps. Here's basically what I'm doing right now: #!/bin/bash param1='something' param2='another' param3='yep' echo $(avro-read /log/huge_data ...
0
votes
1answer
118 views

Bash: Grep regular expression failing to work

When using grep like so: ps aux | grep 'processname' | awk '{print $2}' The PIDs of processes withprocessname is returned. When using this: ps aux | grep '^processname' | awk '{print $2}' I'm ...
1
vote
3answers
611 views

Why doesn't piping grep output into xargs work with color?

I have a strange issue. My grep has colored output, and if I do something like this: grep -lr '80' /etc/apache2/sites-available/|xargs ls I got: ls: cannot access ...
0
votes
3answers
1k views

Bash: Find and replace text strings

I figured this would be easy, but I'm overlooking something simple: I have a text file called test. It contains, for example, the string Alfred Hitchcock. I want to replace this with Alfred\ ...
2
votes
2answers
349 views

Conditional spaces in a regular expression?

Using grep, how would I do this in one command line? I have this so far grep '\$[0-9][0-9]\.[0-9][0-9]' money.txt with various strings in the text file, but I'm having issues satisfying some of my ...
7
votes
3answers
4k views

grep for “term” and exclude “another term”

I am trying to build a grep search that searches for a term but exludes lines which have a second term. I wanted to use multiple -e "pattern" options but that has not worked. Here is an example of a ...
3
votes
5answers
2k views

grep count multiple occurrences

Is it possible to do a grep count of multiple occurrences in a file in one single command? For example: $ cat > file blah alfa beta blah blah blahgamma gamma I can do: grep -c 'alfa' file 1 ...
0
votes
4answers
111 views

Simple script parsing text, what is wrong here?

I'm a big user of https://www.grc.com/passwords.htm to get strong passwords. However, having to go to the site and manually copy the password every time gets old fast, so I decided to do a little ...
2
votes
2answers
83 views

Maintain text colors when wrapping command in bash script

So I've made a small script to search through my project for a word: #!/bin/bash grep -n $1 js/*/**.js grep -n $1 js/*.js When running these commands in the command line I will get some nice syntax ...
7
votes
2answers
1k views

Edit first line of large text file

I have a huge text file, far too big for the whole thing to be paged into memory. All I need to do with this text file is edit the first line (its a CSV file and I need to alter the titles). Is there ...
2
votes
4answers
660 views

How do you remove all occurrences of values in one list from another list?

I have a list of symbols such as... wer sfe efo How do I remove all instances of these (unique) symbols from another list of (non-unique) symbols? So in the following list, the lines starting ...
0
votes
2answers
166 views

Why cat $(find /usr/portage -name *.ebuild) | grep RESTRICT - works? And find | grep - not?

Why I can't grep find? Only helps grepping cat of find. As I see program grep could see some context in which every command runs. But it's counterintuitive for a newbie like me. When given with ...
1
vote
2answers
853 views

How to extract e-mail or domain from mixed data file in linux

File content: 17541 From Email subscription@test.com Inbound Policy Manager Envelope Analysis Profiler 17541 From Email subscription@yahoo.com Inbound Policy Manager ...
1
vote
5answers
2k views

How to grep column after second pipe

Example: 3|100|test@test.com|0|0|6:1,10,11,12,13,2,3,4,5,6,9|7:1,10,11,13,16,2,4,5,6,9| Expected view after grep: test@test.com
0
votes
1answer
828 views

Store grep result in variable

As above I'm running this grep command which works as it should but how do I store the returned value into a variable? cat data.txt | grep "" |cut -d\, -f1 I tried this but it didn't work: ...