Programming :: SQL Substring Matching A Character?
Apr 7, 2011I have the following string:"My dog spot(page 1)". I want just "My dog spot". How do I do this in SQL Server?
View 2 RepliesI have the following string:"My dog spot(page 1)". I want just "My dog spot". How do I do this in SQL Server?
View 2 RepliesI am trying to check if the 9th character in a file on each line is a v and if so, then print the first word. I've tried a number of variations and am stuck !If it's possible to also check if character position 1 begins with a s in the same awk, that would make it cleaner instead of using egrep.
egrep '^s' file | nawk '{virtual=substr($0,9,1); if ($virtual=="v") {printf "%s", $1}}'
nawk: illegal field $(e)
input record number 1
source line number 1
I'm having a small issue with regex matching in Perl. I'm pretty certain it's a simple fix, but it all looks correct to me...
If I run the following:
Code:
It prints out all the lines containing a 'P', as one would expect. But when the regex is
Code:
I get zero lines printed. It seems to match only single-character patterns.
The file I'm reading is: (It has the same effect whether I leave it with Windows linebreaks or convert them to unix).
Code:
I have two table files with x (1st column) ,y (2nd column) coordinates and intensity (3rd column). I need to match these two tables and divide the intensities at the consecutive coordinates on the 3rd column. The problem is the size of the tables are not same and I want to ignore the lines if they are not in one of the other file.
Here is Table 1:
Code:
-7.500-30.00013.006
-7.500-22.50037.952
-7.500-15.00060.962
-7.500-7.50040.922
-7.5000.00014.348
code....
I want normal substring of a string that actually is a url as follows
SITEURL/main.php?page=122&type=download_file&fileID=9&user Id=user1&org=org1&mainmenu=main1&submenu=sub1
What I want is a substring like below
org1_user1_main1_sub1
I've spent most of the evening browsing the web, trying many things I've found on various forums, but nothing seems to work.
I have a test.txt file containing many lines like the following ones :
...
<insert_random_text>228.00 €<insert_more_random_text>
<insert_random_text>17.50 €<insert_more_random_text>
<insert_random_text>1238.13 €<insert_more_random_text>
...
And I want to extract :
...
228.00
17.50
1238.13
...
There is always one occurrence of € in each line. I want the numeric value that precedes this € occurrence. The random text (before and after) may contain numbers too, so the € may be important to parse, in order to correctly identify the number to return. The last character that precedes the number to extract is always a ">" (coming from an HTML tag).
This may be a basic bash array/string operation related question, but I couldn't find any direct answer. So here it goes:I have a lot of data sorted in various directories. All directories need same processing except for a special group of directories. I have a symbolic link of the script in discussion in each directory. I want the script to get the name of the current directory, check if that belongs to special group and do specific operations.So I get the name of the directory
Code:
mm=`basename `pwd``
Now the the group of directories that needs something different to be done, contains these
[code]...
1.What character instructd the shell to interpret a special character as an ordinary character?
2.What directory contains some of the utilities available on the system in the form of binary files?
3. What command is used to search the location of a utility?
4. What command is used to instruct the editor to write the file and quit the editor?
5. What key quits the more utility and displays the shell prompt?
6. What command starts a child shell as the super user, taking on root's identity and environment?
7. Which wildcard characters can be used for searching all the files in the system that start with "A"?
8. The user name or login name of the super user is????
[Code]....
I'm trying to use ${VAR:0:4} substring extraction described here: tldp.org/LDP/abs/html/string-manipulation.html and it works perfectly if i issue a command in bash. But when i put it in a script file and run it, bash gives me "bad substitution" error. Does anyone know how to fix it?
View 5 Replies View RelatedHere's my question. This command replaces "abb" substring
Code:
echo abbc | sed "s/.*b//g"
And this command doesn't work (lazy regex):
[code]....
In a bash-script, only the case if a regular expression does not match is relevant.herefore I used the exclamation mark !. But where to place it?
These two work fine, but are they equivalent?
Code: if ! [[ $abc =~ $pattern ]]; then or
Code: if [[ ! $abc =~ $pattern ]]; then Where is the ! placed more correct?
I need to add some text using sed before and after the matching pattern. Does any one have any clue?e.g.cat /my/file | sed -e "s/first pattern/New Pattern/g" . /my/file.bakNow I need a result like New Pattern
View 7 Replies View RelatedI am struggling to understand why nawk matches values that are either 1 or 2 digits in length, but not 100 (3 digits).
Am I missing something obvious ? Should I use substr to remove the % ?
I am sure it's something to do with character and string matching behaviour with nawk.
Code:
If I have a MySQL field called, say, "Occupation", which contains "Java Programmer" in it, I would like it to come up when I search for "Java", so that I can get to the other fields in the table.
How do I do this?
i tried searching on google but found it difficult to say exactly what I was looking for.Task - Capitalise x number of letters at the start of words.eg. Original line - one.two.three.fourRevised line - One.Two.three.four (here only requiring 2 changes)Test data:
Code:
wire.in.the.blood.s04e01.ws.pdtv.xvid-river.avi
wire.in.the.blood.s04e02.ws.pdtv.xvid-river.avi
[code]...
I'm trying to find out how to extract the string between the 2 <title> tags: <title>this is what i want</title>.I found lots of results but nothing I've tried works.. EG:$page =~ m/<title>($.)</title>/gism;
View 2 Replies View RelatedI have a file which has the words "splashimage and "splash". I would like to remove the word only "splash" from everywhere.
Using the following command code...
Is there a way, preferably in python or BASH, to rename files from a list? for instance, track1.mp3, track2.mp3 should be renamed to the names stored in a file listing song names. I have tried to loop a variable through directory listing and renamed them, only to find that filenames with spaces can't be assigned to a variable as a whole. To solve the problem above, I have tried the read command in BASH, which enables the program reading line by line from a list. However, It was failed to pipe the results from directory listing to the read command.
View 14 Replies View RelatedI have a question about sed programming, actually a one-liner for which I cannot find a solution, right now. I need to delete a line matching a specific pattern only if it is the last line. In practice, I would put together the following:
Code:
#
# This deletes the last line of a file
[code]...
I've been hitting my head against a wall for awhile with this one:As the last part of some data analysis I performing I would to construct a matrix from a series of different files. These files have the format:
file 1 file 2 file 3
AAAAA .1 AAAAA .1 BBBBB .1
BBBBB .2 BBBBB .1 CCCCC .9
[code]...
Quote:Originally Posted by topcatI would like to know how i can write a shell script to delete a line if a particular pattern exists?E.g. I have a text file with multiple lines. Say 1000s. in the following pattern.
username@email.com:149.0.3.4:1
username1@email.com:149.0.3.4:1
username1@email.net:149.0.3.4:1
username1@email.edu:149.0.3.4:1
If the patternusername@email.com exists then the line "username@email.com:149.0.3.4:1 should be deleted from the file.I have a very similar question but I need to delete one line in a file which matches one very precise instance of a string only. Let's assume I have a file composed of thousands of lines and let's call the file chap-secrets. Let's take the following sample entries:
Code:
#USERNAME SERVER PASSWORD IP
pp pptpd blahblah *
[code]....
I have this complex log file filled with entries like
test1-G1/0/0-100-QOS-7001923-ROUTING (ClassMap)
Action: Resolved New
sysName: test1.local
[code]...
I have written a regular expression (tested in regexpal and regextester alpha something) with which I want to replace something like code...
but it only matches functions which occupy one line only, despite my tests showing multiple line matching in javascript testers online and using the m and s flags (which should make it multi line no?)
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'.
I have two files :
FileA
prot1
prot5
prot9
prot15
[Code]....
What I need to do is to extract from fileB the fields containing only the strings in fileA.
I thought awk could do the job easily with :
Code:
awk 'BEGIN { RS = "###" } /'$variable'/' fileB > output
where variable would maybe be the output of grep from fileA. So can I store the output of grep in a variable to use it afterwards with awk ?
something like that:
Code:
result=`grep prot. fileA` ; awk 'BEGIN { RS = "###" } /'$result'/' fileB > output
but that doesn't work. I'm always getting the entire fileB.
The output of grep get stored in the variable, I verified that with echo. So there is something that I just don't get... It seems to me that the above line should work.
I have a string like this "/home/test/filename.txt" and i want to delete all character after the last "/". how to do that using sed or awk.
View 5 Replies View RelatedI was reading Kernighan Ritchie book chapter 4 which deals with character pointers.I am not able to understand following different type of declarations
Code:
char aname[][15] = { "Illegal month", "Jan", "Feb", "Mar" };
char amessage[] = "now is the time";
[code]...
i am compiling the following program in linux. it's in c language. after the compilation with gcc when i run the executable file. it asks for input. but when i enter a name. i prints "Segmentation fault" and then terminate the program. can you please help me.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
[code]....
which is the simplest way to have first and last character cropped out from a string? Something simpler than
Code:
echo $STRING | cut -b 2- | rev | cut -b 2- | rev
I have the following file:
Code:
1 line
...
49 test test=AA:AA:AA:AA:AA=0
I need to substitute on the line number 49, all text until =. I have used the following, but with no actual result.
sed -re '49s/^.+=//' file
and
sed -e '49s/.*[=]//' file