Programming :: Grep Searching For Strings With (apostrophe)

Nov 10, 2010

I am trying a search for a pattern in the file. I can have any character in the pattern. I am pretty sure I will have $, ", ', ^, ` etc., The Problem I am facing is if I use "" (double quotes) to enclose the pattern, it gives special meaning to $, ^ and " within the string. I have no control over the pattern input. I am getting it from some other file. On the other hand, If I use '' (single quotes) to enclose the pattern, it gives special meaning to the ' (apostrophe) within the string and terminates the pattern prematurely. How do I disable the special meaning these characters have? For example, in perl, I could enclose the pattern within Q and E. Is there an equivalent in grep pattern expression? I could find one in the man page of grep. Is there a solution to this problem?

View 5 Replies


ADVERTISEMENT

Programming :: Bash - Searching Strings For Array Elements?

Apr 30, 2010

...and returning the index of the found element in its array.

I have:

for ((i=0; i < ${#array1[@]}; i++)); do
# Read each line of the file test
if [[ $(eval "sed -n '$(($i+1))'p test") == *${array2[0]}* ]]
stuff

I want to find the index of the found substring in array2 and only if it isn't found, move on to the next element of array2. I don't know the size of array2 so that [0] has just got to go.

View 14 Replies View Related

General :: Searching And Replacing Strings In File With Strings In Other Files

Jul 29, 2010

I want to search and replace strings in a file with strings in other files/i need to do it with big strings(string1 is big) and i want to use a txt file for this.But this code not working :

View 14 Replies View Related

Debian Programming :: Searching For A List Of Strings In File With Python

Oct 14, 2013

I'm trying to search for several strings, which I have in a .txt file line by line, on another file.

So the idea is, take input.txt and search for each line in that file in another file, let's call it rules.txt.

So far, I've been able to do this, to search for individual strings:

Code: Select allimport re

shakes = open("output.csv", "r")

for line in shakes:
    if re.match("STRING", line):
        print line,

How can I change this to input the strings to be searched from another file?

So far I haven't been able to.

View 3 Replies View Related

Programming :: Grep - Find The Strings Only Between Begin And End

Dec 15, 2010

if I'd a file like this

something
somethine123
begin something end
begin xyz end
somethingelse

and I want to find the strings only between begin and end, exluding begin and end; How can I grep that?

View 3 Replies View Related

Programming :: Searching Pattern In Tab Delimited File Using Grep

Mar 4, 2010

Suppose i have a file(1.txt) separated by TAB delimiter in a line

1 B AB 2
2 C AB 2

if I need to search for the records having B?? using grep.If i need to perform multiple search like line having "C and AB" or "B and AB"??

View 5 Replies View Related

General :: Grep -- Finding Files That Contain Two Separate Strings?

Dec 9, 2010

I've got a quick grep question. I'm trying to work out a command I can use to locate all of the files in a directory that have sql database connection details. I want to do it by looking for the strings "localhost" and the name of the database.find . -type f -exec grep -l -E '^(localhost|DATABASE_NAME)' {} ;

View 4 Replies View Related

General :: Searching Var/log/updates.log Using Grep?

Jun 24, 2011

What I am usinggrep -B 1 -A 2 "Installed" /var/log/updates.logInstead of tailing the log is there a way to grep all lines of the log with word Installed AND today's date? Also, what about grep lines of the log that contain a specific date and more than one word, by example : ('Installed' or 'Failed' on '2011-06-24')?

View 14 Replies View Related

General :: Searching For PHP Files With Find And Grep

Nov 2, 2010

I am looking for all the files that contain the text string 'moo.sql'. I ran the following:

find . -name '*.php' | grep -lir 'moo.sql' *

Unfortunately it seems to return non-php files in addition to php files. I thought the find portion of this would filter the file names so grep would only search php files.

View 3 Replies View Related

General :: Find / Grep Command Without Searching Mounted Shares?

Jan 5, 2011

When I used the find command, I almost always need to search the local drives. But, I almost always have super large network shares mounted and these are included in the search. Is there an easy way to exclude those in the find command, grep and other similar commands? Example:

find / -name .vimrc

View 1 Replies View Related

General :: Grep - Searching For Class References In C++ Using Regular Expression?

May 28, 2010

I'm trying to math all class references in a C++ file using grep with regular expression. I'm trying to know if a specific include is usuless or not, so I have to know if there is a refence in cpp. I wrote this RE that searches for a reference from class ABCZ, but unfortunately it isn't working as I espected:

grep -E '^[^(/*)(//)].*[^a-zA-Z]ABCZ[]*[*(<:;,{& ]'

^[^(/*)(//)] don't math comments in the begging of the line ( // or /* )
.* followed by any character
[^a-zA-Z] do not accept any caracter before the one I'm searching (like defABCZ)
[]* any white space (I can have something like ABCZ var; )
[*(<:;,{& ] followed by ( * < : ; , & { (I cant get #define "ABCZ.h" or ABCZdef for example)

Well, I can get patterns like this:

class Test: public ABCZ{
class Test: public ABCZ {
class Test : public ABCZ<T>

[code].....

View 2 Replies View Related

Ubuntu :: Searching WITHIN Doc - Xls - Ppt Files - Grep Is Unable To Locate Text INSIDE File Types

Sep 1, 2011

I am on Ubuntu 11.04 and using Libre Office 3.3.2 to compose new documents and am saving them using .doc, .ppt and .xls files. (due to having to share them with others who are on Windows systems)

I have a lot of doc files and I need to search for text INSIDE these files. I am perplexed with the fact that no search tool is able to search for text INSIDE these file types. "cat" can display them of course, but grep is not able to locate text INSIDE these file types. I even tried to save a .doc file as an .odt file, but no luck. The Applications>Accessories>Search for Files does not search INSIDE doc, xls or ppt with the option "Contains the text".

View 6 Replies View Related

General :: Using Find Or Grep To Find A Group Of Text Strings?

Feb 28, 2011

I have used diff command in past.I faced a situation to which I did not had a cluehere are some text strings (which can be stored in a file)Quote:

CONFIG_XEN=y
CONFIG_XEN_PVHVM=y
CONFIG_XEN_MAX_DOMAIN_MEMORY=128

[code]...

View 3 Replies View Related

Programming :: Input File - Grep Within Grep

Nov 22, 2010

I need to kind of grep within grep. My input file would be something like:

[Code]....

and I need to find the first occurrence of hello before MY PATTERN (hello 9008 in this case), so the output should be:

[Code]....

View 4 Replies View Related

Programming :: Searching For Video Or Screen Cast Which Shows Device Driver Programming?

May 30, 2010

I did searched you tube but my results were not great.I have 2 books on KernelProgramming.I feel I need if some where I can get a video tutorial which can help me to understand how to develop a Linux Device driver that will be great.I had a look at Greg Kroah Hartmans video lecture of developing patches on ......I have been reading books and a lot of stuff.So I wish if I could get a video lecture that would be better

View 1 Replies View Related

Programming :: Using Sed To Change Strings?

Sep 3, 2010

I am having a lot of problems trying to change one string by another using sed: the sentence is like this:

sed -i 's/KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="0660"/KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="0666"/g' 50-udev.rules
it is just to fing the line with:
KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="0660"

[code]....

View 8 Replies View Related

Programming :: C Truncating Strings

Dec 11, 2009

I wrote this small program that will truncate a string that's entered in by the user.An example of its usage:if the user enters in a string say "abcdefghijklmnopqrstuvwxyz" the program will only take the first 9 characters and truncate the rest so that the user can be prompted for a second string and not be worried about remaining characters left in the stream.Now this program works O.K. but I would like to find something in C that has this functionality build into it...Does anyone know of any function that will accomplish this.

View 1 Replies View Related

Programming :: Replace Txt Between 2 Strings?

Aug 4, 2010

I am trying to replace a section of a file between the first instances of the strings {}, with the contents of another file. Example of the format of the file I'm trying to modify

Code:

Servername=something.com
hosts {
macaddress1
macaddress2

[code].....

Then captured all the "macaddress#"s to a variable and used sed to swap

sed "s/$CURRENTDATA/$NEWDATA/" filename

However I get 1 of 2 errors,

Using a small number of macs in "$NEWDATA"

sed: command garbled: s/ macaddresshere

Or when using a large number of macs in the $NEWDATA variable get

bash: /usr/bin/sed: Arg list too long.

how to replace a large block of txt in one file with another large block from another?

View 6 Replies View Related

Ubuntu :: Apostrophe In Perl Script?

May 6, 2011

Obviously I want search every .doc file in the current directory, look for the phrase MY COMPANY and replace it with Tonys Restaurant, but I�d rather it be Tony�s (with an apostrophe). perl does not seem to like that. Is there anyway to overcome that? Or should I be going about this a different way? I apologize, but all the Google results were either way over my head and more than I need to accomplish, or they seem to suggest that I can escape the apostrophe, as I�ve done with the spaces, but this does not work.

View 2 Replies View Related

Debian Programming :: Sh Command Strings

Feb 8, 2014

I use udhcp with some of my minimal installs. I've messed around with the code a bit when it wasn't working correctly - a few years ago. I will find time - I hope soonish - to figure out how to do a few other things with it.

For now though, I'm using this string to grab my ip after startup

Code: Select allsu -c 'ifconfig eth0&&ifdown -a&&ifup lo&&ifup eth0'&&/sbin/ifconfig eth0

I realize I could substitute ifup -a but I'm more interested in figuring out how to make ifup wait for the ip to become available if it is not available yet.

Never mind that one, just typing out the question answered it for me, when I find it in the scripting man ' ; : " & =

Or if there are any other suggestions for better construction of the string.

View 2 Replies View Related

Programming :: Extracting URLs From Strings?

Jun 28, 2009

I have a PHP script written that is checking a string to see if it contains a link in it (i.e. a URL). I have the following if statement, that uses 3 possible regular expressions to determine if there is a link or not.

Code:
// check if we found a link
// links are denoted by strings that:
// - contain http://
// - contain www.*.*

[Code]....

I'm not convinced yet that writing a shell script to do this is the best course of action. If someone is capable of doing this with a Perl or a Python script that's fine too. If you want to make it super high performance and write it in assembly

View 1 Replies View Related

Programming :: Best Command To Use To Parse Strings?

Mar 24, 2010

what is the best command to use to parse strings?I have a variable $str and need to parse this string.Can you provide an example of the command used to get a substring of $str based on the index values of start and end

View 3 Replies View Related

Programming :: Cannot Match Strings That Appear To Be Identical

Feb 25, 2011

i have an sql table with 2 columns i run a script that randomly selects a word from the table in column 1.
the word is displayed on the screen and I guess what it means i concatenate the randomly selected word and the answer the script looks for a match in mysql if it finds a match it says "Good job!" if there is no match it will say "not correct". However when i get it right it says not correct even though when i echo the variables they look exactly the same. the script below:

#!/bin/bash
var=$(mysql translator -u root --password=*-N<<EOF
SELECT word FROM tagalog ORDER BY RAND() LIMIT 1
EOF
)

[Code]....

View 4 Replies View Related

Programming :: Get The Strings That Matched Sub-expressions?

Jun 8, 2010

Using the regex.h functions, how do you:

1) get the matched strings?

2) get the strings that matched sub-expressions?

View 4 Replies View Related

Programming :: 'strings' Binary From Binutils - How To Use It

Jul 14, 2010

it is about 'strings' binary from binutils. I recently wanted to test what it does and how it works. The best I did was this:

Code:

#!/bin/sh
PROGRAM="
int main()
{

[code]....

Ok, from the output I don't get it.Can someone show me in a simple script, what is 'strings' good for ?

View 10 Replies View Related

Programming :: Variable Strings In A Script?

Sep 5, 2009

I have a set of numbers under some headers in a file:

FNUM,BNUM,C1N,C2N,C3N,C1S,C2S,C3S,
4535, 109, 5.5955, 5.6523, 5.8084, 311.419, 295.2540, 286.9984,
4536, 109, 5.7667, 5.7174, 5.6771, 291.782, 285.0646, 271.5945,

[code]...

View 2 Replies View Related

Programming :: Working With Strings In An Xml File C++?

Mar 7, 2011

I have a function that retrives text between title and links tags from an XML file, but what i want is to test if the title and link tags are between item tags. This is my code:

Code:
istringstream iss(content);
string line;

[code]...

View 1 Replies View Related

Programming :: Handle Query Strings Using Socket?

Dec 7, 2009

I need to make a daemon which listens to port 81 for messages like [URL] So far I made a daemon which serves as a simple stream server: I set up a socket to listen to a non-reserved port (like 9999), but I don't know how to read the query strings.

Linux distro: Kubuntu 9.04
Language: C

View 5 Replies View Related

Programming :: Implement Variable Substitution In Strings?

May 6, 2011

I have an interpteter that supports string literals, and the way it works is that the lexer returns the entire string as a single token, with the quotes removed and escape sequences replaced with the literal characters they represent.

I already implemented single-quote strings, they don't interpret any characters specially except for the single quote. I partially implemented double-quoted strings, they already support all the same backslash escape sequences that C does. But I would also want to add variable substitution.

The way it would work is that "${expression}" would interpret the expression (which could just be a variable name) and replace itself with the result. But I have no idea how to do this.

In case it matters, I'm using a hand-written lexer and recursive-descent parser.

View 14 Replies View Related

Programming :: Match Strings Inside 2 Lists?

Jul 8, 2011

I have that script that checks the nfs mount points:

Code:
#!/bin/ksh
#set -xv
test="DO_NOT_DELETE"
rc=0

[Code]....

I am no expert in loops and it took me all day to write that. I couldn't really tell how to match the string in $df_file and $fs_share, so I did a little workaround with a count.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved