Programming :: Write Regexp That Matches String That Begins With Whitespace Or Contains Newline?

Dec 10, 2010

How do I write a regexp that matches a string that begins with whitespace or contains a newline, but not necessarily both?

View 2 Replies


ADVERTISEMENT

Programming :: Bash Regexp String Compare Stopped Working?

Oct 20, 2010

Have a bash script which contains a line like this:

if [[ ${array[${last}]} =~ "screenpc.PRODUCTION.*" ]]

which WORKED as expected in bash 4.0.33 and now fails in 4.1.2

Instrumented the script to print the value of the left-hand side and it is exactly what is expected.

As noted above, this has been working fine until we installed Fedora 13 (kernel 2.6.33), and now it fails.

Tried setting shell 'extglob' to On with same results.

Did something change? Are there other shell/bash options that need to be set?this has the whole installation stopped!

View 10 Replies View Related

Programming :: Write A Function That Counts The Number Of Occurrences Of A Pair Of Letters In A String?

Sep 9, 2010

Some help with this problem:Code:Write a function that counts the number of occurrences of a pair of letters in a string

View 13 Replies View Related

General :: Use Regexp In Diff / Exclude Lines That Contain The String "[skipthisline]"?

Feb 10, 2011

I need to compare 2 files using diff. The problem I've encountered is that I need to exclude certain lines that contain certain phrases. I know that diff supports the -I switch but no matter how I try to form the regexp it doesn't seem to work the way I expect it to. If anyone has used the -I switch before could you please post some examples of how it is used.

diff -I "[skipthisline]" file1 file2 > output.diff

I need to exclude lines that contain the string "[skipthisline]" but I have no idea what syntax is used after the -I switch. Is is supposed to be included in quotes or slashes /[skipthisline]/ or entered without either? I need to include a backslash before each bracket so that it's not interpreted as a set of characters like [a-z] but is instead interpreted as a string. Do I need to use 2 backslashes? "\[skipthisline\]"

Is it sufficient to simply type the string I want to match or do I need to match the entire line in order to exclude it from the output?

.*[skipthisline].*

or

^.*[skipthisline].*$

View 2 Replies View Related

Programming :: Bash - Read File Without Whitespace?

Mar 14, 2011

I am struggling with Bash scripting at the moment (I can't seem how anyone can write scripts with this language!!!) I have a need at home to have a cron job execute daily to lookup my downloads.txt file, read each url (per line) and download content from that url. Then that entry needs to be removed (well I keep all urls in memory and clear the file afterwards). If an error occurred during the download process, then the url is written to a downloads.err file. I got all the above working except for properly reading the url from the text file without including newline characters. I am using the following to read:

while read url; do
--Do whatever here--
done < downloads.txt

How can I get it not to let the url variable have newline characters?

View 11 Replies View Related

Programming :: Copy String A To String B And Change String B With Toupper() And Count The Chars?

Oct 22, 2010

copy string a to string b and change string b with toupper() and count the chars

View 3 Replies View Related

Programming :: Migrate Regexp From SED To AWK?

Apr 22, 2010

I have a sed script to search and replace a pattern on the next kind of text:

Code:
C/username/Mydocuments/games & music
C/username/Mydocuments/New files 09-17-2007
C/username/settings
The script is:
code....

View 9 Replies View Related

Programming :: Bash: Regexp In 'if' Doesn't Evaluate Correctly

Mar 1, 2011

I'm using an 'if' statement to check whether one of positional arguments is a word or a construction like "x-y", but something doesn't seem right.

Here is the relevant part of the code:

Code:
if [[ "$3" =~ [a-Z]-[a-Z] || "$3" =~ [a-Z] ]]; then
grepRange=$3; else grepRange=$4
fi
And for the input like this:

[Code]....

but shouldn't the $grepRange variable be blank in this case?

Bash version is 4.1.7(1)

View 6 Replies View Related

Programming :: Prevent Sed From Replacing With Newline

Nov 28, 2009

I'm writing a script to replace some text that exists in about 50 .lex, .y, and .cc source code files, sometimes more than once in a file. Sometimes the text is in a multiline C comment, and other times it's within a multiline C string.

I use sed to grab the start and end of each line and wrap the new text in the old whitespace and/or quotes and Problem is, sed is changing the characters into a newline.

Is there a way to tell sed to not process escape sequences? I tried using several variations of

Code:

To no avail. Or could it be bash?

I would give up on the script and do it by hand, but this is something that I must do from time to time.

Here's the function which replaces the first occurrence found:

Code:

When $post is printed by echo, it shows the - but by the time the file is on disk, it becomes a newline. What should I do to ensure that it stays as the characters ?

View 4 Replies View Related

Programming :: Sed Command To Replace 7th Tab With Newline

Mar 11, 2011

I have a tab delimited file. I need to replace the 7th tab with a new line.

I tried the following command (but it does not work):

The above simply spits out the original file.

If I write the next command, it replaces the first tab in each line with a newline. How can I make it replace the 7th tab in each line?

View 4 Replies View Related

Programming :: Using An Alias Or Function Without The Newline?

May 1, 2010

I want to create an alias or function that when used prints something like this on the command line so I can further modify it before pressing enter myself.

Code:
$ FILE=exercise1; cc -o $FILE $FILE.c && ./$FILE; FILE=
The idea is that I'm studying c and want to change the name of the file once instead of

[code]....

View 3 Replies View Related

Software :: Replace Newline Pattern In File By Other Newline Pattern In A Shell Script?

Nov 22, 2010

I have several (vhdl) files containing a pattern with newline characters that I need to replace by another pattern that also contains newline characters.

I start with something like:

Code:

I want to replace it by something like:

Code:

(I need to paste some lines)

As I need to do this (very) often I want to use a shell script.

I tried:

1.

Code:

result:

Code:

2.

Code:

result:

File remains unchanged

3.

Code:

result:

Code:

4.

Code:

result:

Displays the unchanged testfile

How I can automate the pattern replacement?

Code:

View 9 Replies View Related

Programming :: Inverse Regexp Matching / Developing Of An Idea 'pattern Based Filtration'?

Sep 3, 2010

I am interested in the following problem: given a string (pattern) find a regexp which match this pattern.
I will need this for a developing of an idea 'pattern based filtration'.

View 3 Replies View Related

Programming :: Inserting Multiple Lines - With Newline - Using Sed Or Awk

Mar 8, 2009

I need to replace part of a line in a file with multiple lines, however need to separate each line with a newline is this possible?

Example, need to remove line 2

And insert line similar to below:

If the multiple lines were part of a text file, would inserting a text file automatically include newline characters?

View 1 Replies View Related

Programming :: Adding Form Feed After Newline For Windows?

Apr 27, 2010

I can't get x to work with a mouse so I have to use a windows computer to do that from for now. The problem is I remember there being something about windows using a newline AND carriage return and linux just using a newline. I was about to cut and paste code but the lines go on and on instead of breaking off where they did in linux. I was going to write a perl script but don't know how to add a carriage return to the end of each line.

View 3 Replies View Related

Programming :: Bash If *sometimes* Fails To Detect Embedded Newline

May 21, 2011

Using xsel I pass a selection into a variable. I then check that the variable includes an embedded newline to be sure that the selection returned by xsel is complete. If the selection content preceding the newline is just a single word, the check fails to detect the newline, thus

Code:

g fnm=`xsel`
g cat <<< "$fnm"
Whatis
apropos sear

[code]....

View 14 Replies View Related

Programming :: Pthread - Take String From The Command Line And Creates A Thread To Print The String

May 3, 2011

I've been trying to understand pthread in C a little better. So I made a simple program that takes in a string from the command line and creates a thread to print the string. I've looked online and copied the basic concepts but there are something things I'm confused about. The programs works just fine, but I have questions. Here's what I have so far.

[Code]....

One thing I'd like to know is why the 3rd argument in the pthread_create function which is my SendMessage function needs to be typecasted to a void pointer and then send the address of the function. Also as for the 4th argument, I would see typecasting to void pointer in some of the pthread examples I saw online, but in my case I'm passing a char pointer, would this be correct? In which case would I ever want to pass a void pointer?

Do I need a pthread_exit(NULL) in my main and in the SendMessage function? If so, why? I added the sleep() function so that I could let the pthread_exit function in my SendMessage function execute first. I simply saw that the online examples on pthread had pthread_exit() in both locations.

View 6 Replies View Related

Programming :: Pty Programming-Extra Newline ?

Nov 11, 2009

I'm having a hard time figuring out why the program posted below prints an extra newline every time I type the enter key.This program is using the master pseudo-terminal to send the password and receive the output from the slave(connected to the passwd program).I suspect this has to do with the terminal line discipline(s)(2 considering the master and slave), but I can't really understand why.I have tried turning on/off several terminal special characters but to no avail.

Source code follows(compiled in x86, Slackware-13.0 - linux-2.6.31.5 - gcc 4.3.3):

Code:

View 14 Replies View Related

Programming :: Sed -n '/pattern/{n;p;}' Is Missing Matches In File?

Jun 16, 2011

I have an interesting problem, sed '/pattern/{n;p;}' file, doesn't seem to be catching all of the matches in my file. As an example of this see below.test:

Turn
Turn
Turn

[code]....

View 5 Replies View Related

Debian Programming :: Check If Login Password Matches What Have Specified

Feb 26, 2014

I'm trying to create a program that will go through a list (one word at each line) from the file pwdlst.txt and try to log-in with the passwords entered in the file. When the program tries with a password that matches the current one, the program will stop and print out "The password is: %s" % password. This is what I created so far:

Code: Select allimport urllib
import urllib2
import cookielib

[code]...

get the error and print when the log-in attempt is deniedgo through the list (pwdlst.txt) and try each password one at a timestop the program when the password matches

View 2 Replies View Related

Programming :: Using Sed Replace Line Containing Particular String By A Single String?

Oct 16, 2010

I have a set of lines as ahown below:

Leon went to school
Leon came back from school..
Leon had dinner...

I have to replace the line containing "dinner" by a single string LUNCH...

View 2 Replies View Related

Programming :: Creates String Suffixes Out Of A Reference String?

Feb 25, 2011

I need to creates string suffixes out of a Reference string. for eg. suffixes of abcdefg will be

1)bcdefg
2)cdefg
3)defg
and so on...

create an array of pointers to point to the first few characters and then use that pointer to print the rest of the string.But when i print using the pointer i get GARBAGE values! shudn't std::cout<<ptr[w] print the string following the char it is pointing to? why do i get garbage values?

View 9 Replies View Related

Programming :: C - Put A Specific Arbitrary Part Of A String Into It's Own String?

Apr 18, 2010

So if I'm given a location of a file like:

How can I just take the type of the file at the end? I know I can use strrchr() for a period to get the pointer to the period just before file type. Is there a build in string function that will just take the rest of the string from a certain point on forward in the string? I know it wouldn't be much work to make it myself, but I figured I would find out if it already existed before doing it.

View 9 Replies View Related

Programming :: Convert String To Integer Back To String C++ ?

Mar 13, 2010

Code:

The error is:

Code:

What I want to do is take input of ip4 as a string, convert it to an integer to add 1 to it, then reconvert it back to a string. Its not working.

My full code is:

Code:

View 1 Replies View Related

Programming :: Regular Expression To Match URL Matches Fragments - Python?

Aug 26, 2010

I have made this:

Code:

from urllib import urlopen import re

current_site = urlopen("http://www.krak.dk/").read()
search = re.findall("((http://|https://|ftp://)|(www.))+(([a-zA-Z0-9.-]+.[a-zA-Z]{2,4})|([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}))(/[a-zA-Z0-9%:/-_?.'~]*)?", current_site)

[code]....

I only want to match complete URL's. how do i avoid matching the fragments ?

View 4 Replies View Related

Programming :: Assigning Custom String To Std::string In C++?

Oct 12, 2009

I've been given a custom-made string class which handles string, wstring and bstr. It has a number of methods and assignment operators to convert to and from different types. The app I work on compiles happily in VS6 and VS2008, but when trying to compile in Redhat (version 4.1.1 in Redhat 5.0)

[code]....

View 4 Replies View Related

Programming :: How To Check If All Letters Of One String Are In Another String?

Nov 11, 2010

I have the following two type of strings1: A/D2: A/C/DI am trying to write a subroutine to check whether all of the letters in string 1 appears in string 2. If yes, return true. If not, return false. In the above example, all the letters (A and D) in string 1 are also present in string 2, so I return true.

View 4 Replies View Related

Programming :: Shell Script To Delete Part Text Of A Line If Pattern Matches?

Apr 12, 2010

I am trying to create a shell script, on taking a input file as parameter, which need to do 3 things

1) create a copy of existing file.

2) add a new line to the copied file.

3) strip off all the absolute paths inside the copied file

The first 2 points are straight forward. but i am finding it difficult to acheive the 3rd point. myself not very good with awk and sed. but gave it a shot in vain. For example, the input script consists of below,

PROGRAM=`/usr/bin/basename $0`
HOST=`/usr/bin/uname -n`
echo Start $PROGRAM `/usr/bin/date` |
/usr/bin/tee -a $LOG

The output of the script should look like,

PROGRAM=`basename $0`
HOST=`uname -n`
echo Start $PROGRAM `date` |
tee -a $LOG

View 14 Replies View Related

Programming :: Sed Delete Lines From File One If Regexp Are Listed In File Two?

Sep 17, 2009

I am trying to delete lines of a file if they contain text that is present on another file. For example

> cat one.txt:

a
b
c
d

[code]....

I get the following output:

> ./test.sh one.txt two.txt
a
b
d
e

[code]....

View 6 Replies View Related

Programming :: Convert The Int To A String Using Stringstream Then Convert The String To A Char?

Mar 26, 2011

Do I have the convert the int to a string using stringstream then convert the string to a char? or is there a more direct way?Also is there a way to tell the length of a int?

View 5 Replies View Related







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