Tagged Questions
1
vote
2answers
61 views
Split using sed
I have to split
[X] ||| you owns the [X,1] ||| you own the [X,1] ||| 1 0.02020 0.07847 0.36788 3 -0.00000 -0.00000
at the pipes and output those line whose 2nd and 3rd argument are different.
2
votes
3answers
78 views
Very strange behavior with grep and IFS
I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character...
This is the script sample :
OLDIFS=$IFS
IFS="\\n"
i=$(grep -ril $1 *)
echo $i
IFS=$OLDIFS
...
5
votes
3answers
201 views
difference between .* and * in regular Expression
I've a file named "test" that contains
linux
Unixlinux
Linuxunix
it's linux
l...x
now when i use grep '\<l.*x\>' , it matches :
linux
it's linux
l...x
but when i use grep '\<l*x\>' ...
1
vote
1answer
77 views
What is a sure fire way to find all files and/or path that contains 2 keywords?
I was doing a
find . -iname '*sitesearch*' | grep demo
because I know the file should be some/path/SiteSearch/demo/SiteSearch.html, but it turned out a person put the file in as ...
0
votes
3answers
129 views
Regular Expression for finding double characters in Bash
I am looking for a regular expression that finds all occurences of double characters in a text, a listing, etc. on the command line (Bash).
Main Question: Is there a simple way to look for sequences ...
1
vote
2answers
133 views
Regular expression problem(s) in Bash: [^negate] doesn't seem to work
When I execute ls /directory | grep '[^term]' in Bash I get a regular listing, as if the grep command is ignored somehow. I tried the same thing with egrep, I tried to use it with double and single ...
0
votes
1answer
107 views
ps | grep shows bad output in subshell with jobs running in the background
I am using bash. I have a file named "a2draw" that contains only 1 line:
sleep 99999
I start it using this command:
bash a2draw &
Now, I know and understand the trick with square bracket ...
4
votes
4answers
67 views
Bash-completion and grep
I installed a program (iftop) on Debian Squeeze but some days ago I forgot it's name.
I had only this information about the program:
1) It was called *top
2) I could find it using bash-completions.
...
2
votes
2answers
109 views
find all cpp files and list only those files with names that match a pattern (regex) does not work
I have a whole repository of files and I am trying to get a list of files that match a certain criteria.
For example, let us say that I want to take all the files that have the string foo1 and ...
2
votes
2answers
118 views
Use of quotes in GNU grep regular expressions
I could see that certain patterns in the GNU Grep can be enclosed within brackets and certain others need not be. For example, matching the beginning of a word works only if it is enclosed within ...
1
vote
2answers
114 views
How to run grep and show x number of lines before and after the match [duplicate]
grep returns just the line where it matched the regex and often what I want to really see is a few (say 2) lines above and below the matched one.
Is there a simple way to achieve it?
EDIT:
OS: Ubuntu ...
3
votes
3answers
46 views
How to separate numerical values from identifiers
I'm currently writing a shell script that seperate values from their identifiers (retrieved from grep).
For example, if I grep a certain file I will retrieve the following information:
value1 = 1
...
1
vote
2answers
137 views
How to use tail -f with grep to show surrounding lines
I would like to see the output in a logfile greped by only one domain but also the following two lines.
Example:
tail -f /var/log/apache2/modsec_audit.log |grep mydomain.de
this shows all lines, ...
4
votes
2answers
176 views
how to use grep for specific files?
for example I type
ls -altr | grep "23 Dec"
so it will show files for 23 Dec only and I want to use grep for them, like
ls -altr | grep "23 Dec" | xargs grep -l "some_string"
but this doesn't ...
1
vote
3answers
121 views
How can I use grep to search for lines that start with a certain character in bash
I want an alias ('ggg') that will look through my existing set of aliases and tell me all the ones that begin with g. I have a lot of g* aliases :)
I tried this: alias ggg='alias | grep ^g' but ...
3
votes
1answer
385 views
Modify /etc/xdg/lxsession/LXDE/autostart before boot
I have some parameters that I would like to change in /etc/xdg/lxsession/LXDE/autostart, before it is run. I get the parameters from a grep command. I would like to feed them to the autostart file but ...
3
votes
5answers
534 views
Output multiple files from a single grep?
I'm not very experienced in shell scripting, but I'm trying to understand how to grep for a pattern and for each file where there is a match write a file to disk that contains the matched line from ...
1
vote
3answers
795 views
Linux: Does find | xargs grep have limitations?
I've historically performed something like:
find . 2>/dev/null | xargs grep -i something_to_find 2>/dev/null
If my pwd is barfoo (/foo/bar/baz/foofoo/foobar/foobaz/barfoo) it finds matches. ...
6
votes
2answers
381 views
When is it useful to use “grep — SOMEPATTERN”?
So under Linux/AIX where ever.., when is it useful to use:
grep -- SOMEPATTERN
the Question is the "--" part. When is it usefull to use?
0
votes
4answers
524 views
How to detect dos format files in git bash
Git Bash is a nice bash shell you get in Windows as part of the installation of Git. It comes with other typical unix tools bundled inside, such as grep, sed, awk, perl. It doesn't have the file ...
6
votes
3answers
1k views
What is the difference between grep -e and grep -E option?
I am trying to understand the difference between grep -e and grep -E. Now from grep manpage I got:
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (see below).
...
1
vote
3answers
561 views
bash merge 2 lists removing duplicated
I have an embedded linux system using Busybox (OpenWRT) - so commands are limited. I have two files that look like:
first file
aaaaaa
bbbbbb
cccccc
mmmmmm
nnnnnn
second file
mmmmmm
nnnnnn
...
3
votes
4answers
259 views
Why does grep not work with redirection?
Using the top command with redirection works fine:
top > top.log
Now I want to use grep to filter a certain line:
top | grep "my_program" > top.log
But the log file will remain empty. But ...
3
votes
2answers
480 views
How do I use tee to redirect to grep
I don't have much experience of using tee, so I hope this is not very basic.
After viewing one of the answers to this question I came across a strange beheviour with tee.
In order for me to output ...
2
votes
5answers
495 views
Need to grep file with specific letter and move to another folder linux
I need to select files which contain "Error" or "traffic" in their names, e.g.
abc_ERRor.csv
raError.csv
bsn_Error.csv
bbbctraffic.csv
ccc_traffic.csv
...
and move them into corresponding ...
14
votes
3answers
873 views
Piping from grep to awk not working
I am trying to grep the ongoing tail of file log and get the nth word from a line. Example file:
$ cat > test.txt <<EOL
Beam goes blah
John goes hey
Beam goes what?
John goes forget it
Beam ...
4
votes
1answer
708 views
Bash, remove lines containing string with grep
This is currently deleting the whole contents of the file in question:
#!/bin/bash
rpc_port="9201";
dir="/etc/apache2/ports.conf"
cat $dir | grep -v "Listen $rpc_port" > $dir
The file contents:
...
2
votes
1answer
153 views
Oneliner to detect camelcase variables
I would like to insert some style tests as git hooks in order to stick with precise style rules.
How can I come up with a oneliner that detects and prints arbitrary camelcase variables like the ...
6
votes
1answer
249 views
Peculiar piping grep/head behavior
I'm helping the netadmin here with a perl regex to automate operating on some snapshots from our SAN and our scripts does stuff like this:
varinit1=$(iscsiadm -m session | grep rbmsdata1 | head -n1 | ...
1
vote
4answers
671 views
Grepping over a huge file performance
I have FILE_A which has over 300K lines and FILE_B which has over 30M lines.
I created a bash script that greps each line in FILE_A over in FILE_B and writes the result of the grep to a new file.
...
7
votes
4answers
13k views
How do I grep for multiple patterns?
I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing
grep (foo|bar) *.txt
but the shell interprets the | as a pipe and ...
4
votes
1answer
119 views
How can I act on the results of the “locate” command?
I'm trying to find where check_dns is defined in nagios' commands.cfg file, although there are quite a few files.
I know I could run something like find / -name "command.cfg" -exec grep check_dns {} ...
2
votes
5answers
3k views
make grep output without trailing newline
Please consider this snippet:
X=$(grep -m1 'some-pattern' some-file | sed -n 's/.* //p')
I want to put last word in a variable if some pattern condition is matched for lines in arbitrary text file
...
3
votes
3answers
403 views
Extracting text from a text file in bash
I have a large text file that is all one line. In the text are several sections that looks like foo=12345 and I need to extract them all as separate lines, ignoring the rest of the file.
For ...
3
votes
5answers
180 views
evaluate multiple patterns from program output and write into pattern specific files
I have a script outputting some value/numbers and I want to split those into two files. I am looking at something like:
./runme.sh | grep 'ook' >> ook.out | grep 'eek' >> eek.out
Where ...
0
votes
1answer
352 views
grep searchstring /etc/crontab strange behavior in BASH script
I am working on a BASH script which creates automated backups via the crontab. I am trying to use
myVARIABLE=`grep backup /etc/crontab`
to return lines containing "backup" if an entry has already ...
4
votes
4answers
3k views
Grep: how to add an “OR” condition?
I am a total regex newbie. I find it confusing and I avoid it like the plague (wanna take some guesses as to why I'm not good at it?). But I suspect it might be the solution to my question. Which ...
2
votes
3answers
557 views
How to cut the output to only gather the filename and get-parameter?
I have multiple files with multiple links that are formatted like this:
<a href="http://example.com/fnord.layername.html?parameter=FOO-_-BAR-_-FNORD" class="poit">
<img ... />
...
4
votes
2answers
2k views
Looking for a Java class in a set of JARs with find, unzip, grep
I was trying to find the JAR containing a Java Class. JARs are in zip format.
My first attempt was:
$ find -name "*3.0.6.RELEASE.jar" | xargs -l1 unzip -l \
| grep stereotype.Controller
...
1
vote
4answers
9k views
count number of lines, bash grep
Hello I am grepping results to file, and then doing cat to show its content on the screen, I want to know how many lines of results I have in my results file and the += it to some counter.
What will ...
1
vote
2answers
1k views
Why does adding a colon break this grep pattern?
I executed a search with grep, but it doesn't work like I expected it to. I have the following lines in a file:
blacklists/redirector/domains:needyoutube.com
...
3
votes
1answer
317 views
grep and brackets in text
I store downloaded files in a log like this:
[source] filename
To avoid downloading a file more than once I grep for [source] filename before:
if ! grep "$signature" downloaded.log > ...
1
vote
2answers
523 views
How to group grep results?
I have a file that contains results grouped into categories. For example:
checking results for $var
here are some results1 for $var status ok
here are some results2 for $var status ok
here are some ...
3
votes
3answers
852 views
executing multiple greps in a single find command
I want to use find command to find some files containing multiple patterns at the same time.
I tried something like this:
find . -name "*.xml" -exec grep -iH keyword1 + && grep -iH ...
2
votes
3answers
754 views
Why is grep -o -w not giving me the expected output on Mac OS X?
If I do echo foo bar baz | grep -o -w baz the output is foo bar baz (and an extra newline).
The expected output would be baz as the -o option should only display the matched part.
I'm using Mac OS X ...
6
votes
1answer
6k views
Bash: assign ls | grep to a variable and echo it with a string
I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got:
#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
...
5
votes
3answers
1k views
how to execute lines coming from a grep result?
I've got a text file with certain installation instructions, and I know I can grep for a unique occurrence in the file. For example, the text file has something like:
MYDIR=`find /home/user -name ...
4
votes
2answers
3k views
giving grep output to rm
I'm trying to pipe grep output to rm, but it outputs useless stuff. Is any switch required for rm? Or can rm can be provided a regexp directly?
ls | grep '^\[Daruchini'| rm
rm: missing operand
Try ...
1
vote
4answers
622 views
A problem with find and grep
I have dafined the following in .bashrc:
alias fg='find . -name $1 | xargs grep --color $2'
in order to write
fg "*.txt" " my_text "
and find all file that have extension .txt and contain " ...
2
votes
3answers
2k views
Extracting tokens from a line of text
Using bash scripting and grep/awk/sed, how can I split a line matching a known pattern with a single character delimiter into an array, e.g. convert token1;token2;token3;token4 into a[0] = token1 … ...
