Programming :: Check If A String Entered By User Starts With A Particular Pattern Or Not?
Feb 4, 2010How do i check if a string entered by a user starts with a particular pattern or not?
View 3 RepliesHow do i check if a string entered by a user starts with a particular pattern or not?
View 3 Replieshow to do a small script that checks if what the users entered is an ip address or not? Also possible to do the same but instead of an ip address is a netmask. For example the user entered: 192.168.0.1 so its true this is an ip address, if it doesn't look like an ip address then is false And second example, the user entered: 255.255.255.0 so the script returns true, and if its not a netmask the script returns false.
View 6 Replies View RelatedI am new to perl and not able to understand all the pattern matching.
I using this script to send the status to another Nagios server using ncsa. Nsca don't transmit "()" So I need to remove them before sending.
Currently I am using
Code:
for the string
Quote:
This is working fine but its is not working when there is change inside the bracket for e.g (6290)
I want to change this code to work for any change with in the brackets.
I have a file with a number of strings like the ones below
string1#m1asdfe23easdf23wefas
string2#mfaaeb2vr1rhserh
anotherstring#ji89ensrsegr
anotherone#m1ynmdt324nsdt
I'm trying to delete everything after #** so that
string1#maasdfeaveasdfawefas
string2#mfaaebvrserhserh
becomes
string1#ma
string2#mf
tried sed 's/#..*//g' but as you all will know it returns string1, string2 etc.
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 Relatedi have a file name using the following pattern:
PREFIX: AR
SOURCE: LEGACY
DATETIME: YYYYMMDD_HH24MISS
SUFFIX: .txt
sample filename:AR_LEGACY_20101104_105500.txti want to extract the source which is LEGACY in this case. how do i do this using shell?
I am trying to write a remote access module. Is there any function in linux where I can give string (password entered by user) and compare it with the actual user password stored in /etc/shadow. Since the password is stored encrypted in /etc/shadow I cannot parse and compare. So I want some method to compare if my user entered the correct password..Is there any function for that..
View 6 Replies View RelatedI have a macro which I use with ROOT. In this macro I want to check if a part of string exist so I can ignore it inside a loop. So, inside a loop I want to have something like:
Code:
if (string == "pre_ti_data_bdt*" || string == "pre_ti_data_nn*")
continue;
but of course I cannot use * in this piece of code! How to do this trick in C++?
I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern exists.how do i get the line number of the pattern and delete that line and replace the line with my new text?
View 1 Replies View RelatedI have to enhance the behaviour of a backup script written in perl. I don't need to change it, what I need to do is to create a bash script that does some checks like file name and file size, execute the backup script then check if the backup files match the original files.Here's how I try to do it:
- read the files from the original files folder
- store them in an array
- search in the array the files that have a specific file extension
- store the file names that match the search pattern (I know the backup script skips some files so I can hardcode the search pattern)
- run the backup script
- read the files from the backup folder
- store them in an array
- compare the original files name and size stored in an array with those from the backup folder
- send a report email
copy string a to string b and change string b with toupper() and count the chars
View 3 Replies View RelatedI would like to remove a string pattern which like this.You should not remove this /*This is the part should remove*/ You should not remove this.I would like to remove all the text inside the /* and */.
View 2 Replies View RelatedI'm running PCLinuxOS with no other OS installed. Thought I'd have a go at chainloading. just for interests sake.So, I opened Konsole, entered su and entered my root password. The command line turned red so, I imagined all was well. But when I then keyed in '/boot/grub/.menu.lst' I was refused access.
View 10 Replies View RelatedOne of the feature in my application involve changing of hardware setting. This require the user to be root or have administrative right.Before my application enable that feature, I want it to check whether the user is "root" or not, or whether user use "sudo" command to run the application or not, or whether the user has administrative rights or not.What are the codes or library that can do this?
NOTE: Sometimes, advanced linux user may set the user id of root to something else other than 0. So, getuid() may not be helpful in this case.
I have been searching for 90 minutes for something that I "think" should be fairly easy. I'm pretty new to Bash Scripting so I could be completely wrong. Then again it may be a weird request to even need something like this. But here it is.I have a script written to convert data from one of our software version to another. The only thing I need to add to it is a "check to make sure the user running the script is in the /tmp directory".
View 7 Replies View RelatedI'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.
I need to grep for a particular string and if found need to display the line containing that string, the line above that and also the first line of that paragraph.
Can this be done via sed.
Eg, My Paragraphs
OA connectA
Enclosure:
Interconnect Module #6 Status:
Here, if I grep for Critical, it should display the following
Similarly if I grep for Degraded, it should display
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...
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?
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.
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:
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]....
When trying to install 11.2 from DVD, the user information I entered at the beginning of the install gets lost. I get to the Automatic Configuration step at the end of the install where the computer needs to reboot, and it asks for my user ID and password (it shouldn't do that). It won't accept the user I created (always says login failed), but it will accept root. That really doesn't matter, because the Automatic Configuration step has done anything, and I have a busted install. I've tried the install 4 or 5 times, but it is always the same problem. I eventually reinstalled 11.1 without any problem (though I did have to click Use Entire Disk on the partition section so it would delete the ext4 partitions created by the 11.2 install and create ext3 partitions).
View 3 Replies View Relatedthere is a program will generate a log to the text file , this program will run times per day , can advise if I want to check the text file , if the text file have a string "Uuable to run program" , then send mail to me , can advise what can i do ?
View 4 Replies View RelatedI'm trying to write a script where I want to check if any of the parameters passed to a bash script match a string. The way I have it setup right now is if [ "$3" != "-disCopperBld" -a "$4" != "-disCopperBld" -a "$5" != "-disCopperBld" -a "$6" != "-disCopperBld"]but there might be a large number of parameters, so I was wondering if there is a better way to do this?EDIT:I tried this chunk of code out, and called the script with the option, -disableVenusBld, but it still prints out "Starting build". Am I doing something wrong?
while [ $# -ne 0 ]
do
arg="$1"
[code]....
I'm writing a bash script to search html files, and when I find any occurrence of an img src tag like this:
<img src="123-picture-normal.jpg" alt="some random user entered text" border="0">
I want to add a second line below it that looks like:
<img src="123-picture-thumbnail.jpg" alt="some random user entered text" border="0">
All I need to do is duplicate the line but replace "normal" with "thumbnail"
Each file can have multiple img src tags with different numbered jpgs.
I have a feeling this is a job for sed, but I'm struggling with it. Any ideas?
I want to put check menu & check list in utility dialog.i dont know how i do this
View 1 Replies View RelatedI 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 Relatedif the given pattern exists in the file with the very next line starting and endingwith the same pattern , delete the line that starts and ends with the given pattern.So upon running on this file
hai people<PATTERN> we had
<PATTERN>a lot of fun<PATTERN>
writing scripts
[code]....
I am trying to split a pattern in perl and so far I cannot get it to work. I have a pattern that looks like this:
76|2455311|2455312|00:00:00|00:00:00|Once|0|Donkey | |
I always need to print out the 8th field. So in this case donkey. Here is what I have so far:
Code:
#!/usr/bin/perl
use strict;
use warnings;
[Code].....