grep

How i can do a shell script to know if my connection is up on ubuntu

I'm very low with shell scripts.. I need to check with a cron (no problem for this) if my connection is up. If it isn't, i want to call some scripts to reconnect. I was thinking about using grep and ping to some site (or ip), then check the returned string. Then call my command: sudo pppd call speedtch I need a clue thanks! Or ther...

grep -- find this but not that

To make a long story short, I have a line of text that I'm using grep to see if the letter 'd' exists here is an example of what is going on: echo d file='hello world' | grep -c -w d Returns 1, this is correct. echo file='hello world' | grep -c -w d Returns 0, this is correct. echo d file='hello world d' | grep -c -w d Returns 1, this...

using sed and grep to search and replace

I am using egrep -R followed by a regular expression containing about 10 unions, so like: .jpg | .png | .gif etc... This works well. I would like to then replace all strings found with .bmp I was thinking of something like egrep -lR "\.jpg|\.png|\.gif" . | sed "s/some_expression/.jpg/" file_it_came_form so the issue here is, how do I...

unexpected agrep() results related to max.distance in R

This was tweeted to me by @leoniedu today and I don't have an answer for him so I thought I would post it here. I have read the documentation for agrep() (fuzzy string matching) and it appears that I don't fully understand the max.distance parameter. Here's an example: pattern <- "Staatssekretar im Bundeskanzleramt" x <- "Bundeskanzle...

Free program to grep unicode text files in Windows?

I have a collection of unicode text files (exported from regedit) and I'd like to pull out all the lines with a certain text on them. I've tried Grep for Windows and findstr but both can't seem to handle the unicode encoding. My results are empty, but when I use the -v option (show non-matching lines), the output shows a NUL between ea...

Grep a string recursively in all .htaccess files

How can I grep for a certain string recursively in all .htaccess files? grep -r -n -H -I 'string' .htaccess doesn't seem to work. I'm on a GNU Linux system. ...

bash grep newline

[Editorial insertion: Possible duplicate of the same poster's earlier question?] Hi, I need to extract from the file: first second third using the grep command, the following line: second third How should the grep command look like? ...

How can I ensure a Bash string is alphanumeric, without an underscore?

I'm adding a feature to an existing script that will allow the user to configure the hostname of a Linux system. The rules I'm enforcing are as follows: Must be between 2 and 63 characters long Must not start or end with a hyphen Can only contain alphanumeric characters, and hyphens; all other characters are not allowed (including an u...

Selecting resulting files from grep in vim

After I run a grep search in vim with :grep, I get a list of files. Is there a way to select one of those files and open it in a new tab at that particular line? ...

I’m stuck in trying to grep anything just after `name=`

I’m stuck in trying to grep anything just after name=, include only spaces and alphanumeric. e.g.: name=some value here I get some value here I’m totally newb in this, the following grep match everything including the name=. grep 'name=.*' filename Any help is much appreciated. ...

[Python] `cat filename | grep -B 5 -C 5 foo`

for filename in os.listdir("."): for line in open(filename).xreadlines(): if "foo" in line: print line So this is a simple python equivalent of cat filename | grep foo. However, I would like the equivalent of cat filename | grep -B 5 -C 5 foo, how should the above code be modified? ...

How can I grep for a text pattern in a zipped text file?

Our daily feed file averages 2 GB in size. These files get archived to a single zip file at the end of each month and stored in a network share. From time to time, I have a need to search for certain records in those files. I do this by connecting by remote desktop to the shared server, unzip the files to a temp folder, run grep (or Powe...

How do I view all ignored patterns set with svn:ignore recursively in an svn repository?

I see it is possible to view a list of properties set on every directory within an SVN repository using proplist and the -R flag (recursive) and -v flag (verbose): svn proplist -Rv This shows me all properties, such as svn:mime-type or svn:executable. I'm looking to filter this to just svn:ignore properties. I'm sure there is some way...

find string inside a gzipped file in a folder

My current problem is that I have around 10 folders, which contain gzipped files (around on an average 5 each). This makes it 50 files to open and look at. Is there a simpler method to find out if a gzipped file inside a folder has a particular pattern or not? zcat ABC/myzippedfile1.txt.gz | grep "pattern match" zcat ABC/myzippedfile2....

Why doesn't my Perl grep return the first match?

The following snippet searches for the index of the first occurrence of a value in an array. However, when the parentheses around $index are removed, it does not function correctly. What am I doing wrong? my ($index) = grep { $array[$_] eq $search_for } 0..$#array; ...

Using awk to get next fields

I have this input file (space is the separator for the two elements in the line otherwise there is just one element) a:1 a:1 123 b:2 345 c:3 456 d:4 d:4 456 .. .. I am interested in the output to be a:1 123 d:4 456 i.e lines which have the preceding field to have just one field. ...

What are some one-liners that can output unique elements of the nth column to another file?

I have a file like this: 1 2 3 4 5 6 7 6 8 9 6 3 4 4 4 What are some one-liners that can output unique elements of the nth column to another file? EDIT: Here's a list of solutions people gave. Thanks guys! cat in.txt | cut -d' ' -f 3 | sort -u cut -c 1 t.txt | sort -u awk '{ print $2 }' cols.txt | uniq perl -anE 'say $F[0] unless $...

To grep efficiently by upward recursion

How can you run the following in Grep? grep "TODO" * grep "TODO" */* grep "TODO" */*/* grep "TODO" */*/*/* grep "TODO" */*/*/*/* I run unsuccessfully grep -r "TODO" I get what I want by ack-grep by ack-grep TODO. ...

Grep and Pipe in Linux

I have a giant file where I want to find a term "model". I want to pipe the first 5 lines containing the word model to another file. How do I do that using Linux commands? ...

How to determine which pattern in a file matched with grep?

I use procmail to do extensive sorting on my inbox. My next to last recipe matches the incoming From: to a (very) long white/gold list of historically good email addresses, and patterns of email addresses. The recipe is: # Anything on the goldlist goes straight to inbox :0 * ? formail -zxFrom: -zxReply-To | fgrep -i -f $HOME/Mail/gold...