Server :: Case Statement With Regular Expressions - Date Manipulation Script
Aug 19, 2010
Here's my need:
If Calendar Day= Then FCPeriod= And FCYear=
Jan 11 to Feb 1002Current Year of Feb 10
Feb 11 to Mar 1003Current Year of Mar 10
Mar 11 to Apr 1004Current Year of Apr 10
Apr 11 to May 1005Current Year of May 10
May 11 to June 1006Current Year of June 10
June 11 to July 1007Current Year of July 10
July 11 to Aug 1008Current Year of Aug 10
Aug 11 to Sept 1009Current Year of Sept 10
Sept 11 to Oct 1010Current Year of Oct 10
Oct 11 to Nov 1011Current Year of Nov 10
Nov 11 to Dec 1012Current Year of Dec 10
Dec 11 to Jan 1001* Current Year of Jan 10
* Note for Dec 11 - Dec 31,
The Next Year to be used
IE: Current date is Dec 28th, 2010. Year = 2011
IE: Current date is Jan 8th, 2011, Year = 2011.
Looks like I'll need a case statement with some regular expressions...
I'm writing a program that works with text files, and I'm trying to create some filters with grep. I have various questions here, so I'll number them for clarity.
1) First of all, I'd like to know what wc -w is actually returning. The word count is less than what gedit is counting in Document Statistics, so obviously gedit is counting something (like newlines) that wc -w is not
2) Secondly, I was wondering if there was a way to grep x number of words. I'm looking for something like the -m option, but returning a certain number of words instead of lines. For example, to find the first 2000 words, do something like grep -someoption 2000 ".*" or using {1,2000}.
3) Finally, I'm trying to filter out headers and footers of a text file but having no luck. The text files are Project Gutenberg files, so they have standardized headers and footers. Here's an example: [URL]...
The header starts with "The Project Gutenberg EBook of" and ends with the line containing "START OF THIS PROJECT GUTENBERG EBOOK" The footers begin with: "End of the Project Gutenberg EBook of" My problem is, grep can find:
I've began to develop with C++ (Eclipse+Qt) and the first problem I see is that there is not good functions for manipulating strings. if there is a library for manipulating strings with regular expressions?
i am trying to create an exclude regular expression for my build.xml. The problem is, that i am trying to find some info on which REs are acceptable/valid for ant... Is ant using standard regular expressions? POSIX ones? Since it is a java-based tool, the "Java REs" are probably valid. I am a little bit confused. If somebody can help me out with the different RE standards, i would be most obliged.
Code: find /Data/ -type f -iname "*7pm*" But this doesn't: Code: find /Data/ -type f -regex *7[Pp][Mm]*
I've tried MANY variations, but I'm getting no error messages, just no returns, and yet the first find, will find the sorts of files I'm looking for. I realise a win is a win, but I'm of the understanding that the -regex switch allows for some really complex use of regular expressions - but I can't even get a very simple one to work,
I am facing problem with the following script. Could you please look into this.echo 'Enter Staging number' case $STGNUM in
1) for i in {'stg1-greg','stg1-marsha','stg1-peter','stg1-jan','stg2-greg','stg2-marsha','stg2-peter','stg2-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/stopwf.sh;done;
the following works and BASH doesn't complain, but VIM highlights the closing square bracket is if it sees a syntax error. Is there a better way to express regex in a case statement or is this an issue with VIM?
I can't get this simple regular expression to work for matching emails: 'w*(?:.w*)*@w*(?:.w*)*w{2,5}'
It should be working as I have tested it with regex pal and it works just fine. I think there's a problem with optional character class but I'm not sure.
I am pretty new at this topic but I would like to learn it from example. The first thing I am working on is to modify the command date to be shown as DD/MM/YY only using regular expression but I dont know how to combine what there is in the regexp tutorials online and the syntax for batch scripting. Any help?
Here is what I what. run a file test: ~# ./test Where file test is: #!/bin/bash # DATE=$( date )
[Code]..
Also if you can point me to good regexp tutorials (directed towards batch scripting), that will be great.
As you can see, I want to pass arguments depending on the option(s) chosen by the user; ie. --snooze, or --channel. By default, if no options are chosen, I'll display a usage message; though in the future I'll provide some sane defaults. I'd like to create a case statement to handle passing arguments to any number of options; something like:
Code:
wakethehellup.sh --snooze 20 --message 'wake up!'
and for the other arguments, it would have a default set. The case statement I provided fails with a syntax error "syntax error near unexpected token `$2'" near the '--snooze' in the statement, so I take it you can't pass a parameter in this way; but I'm confused as to how I'm supposed to pass different parameters to different options without the options being confused as parameters.
Is it possible to point to a two-digit interval with regular expressions?
Background: I'm using mplayer to watch tv shows, that often have episode numbers in their names. I know how to easily add several files to the playlist by using brackets, by typing something like $ mplayer tv/South.Park.S1.E0[1-5]*avi
Is there a way to point to files 06-13 in a single expression?
Lets say I have 20 files named FOOXX, where XX is the number of the file, eg 01, 02 etc. At the moment, if I want to delete all files lower than the number 10, this is easy and I just use a wildcard, eg rm FOO0* However, if I want to delete specific files ina range, eg 13-15, this becomes more difficult. rm FPP[13-15] does not work, and asks me if I wish to delete all files. Likewse rm FOO1[3-5] wishes to delete all files that begin with FOO1 So, what is the best way to delete ranges of files like this? I have tried with both bash and zsh, and I don't think they differ so much for such a basic task?
What I am doing is reading the text from a text document and storing all of the text inside of a ArrayList. I then set one of the values of the Arraylist as a string. I want to use regular expressions find out what the first two characters of the String are. if first two characters = "//" then function(); I only care about the first two characters though. If you need any more information, just ask.
Im a bit stuck with a simple script that im practicing with... im trying to get my head around some simple scripting. Basically i want to write a script that will work as below: It will ask the user to enter their userid. If its correct it will say 'Correct' If its the wrong id (But the ID exists in /etc/passwd) then it will say 'incorrect' If its not a valid userid it will say 'doesnt exist'. What i have so far is:
[Code]...
# If the user enters their own userid they will get a comment saying 'correct' $LOGNAME) echo "Correct";;
# If they enter another users ID (That exists in the /etc/passwd), then they get a message to say 'incorrect userid used'. Im not sure what i need to do here to get it to check the /etc/passwd to see if the input exists in there.... im guessing some kind of simple 'if' statement to say ---- "if 'input' exists in /etc/passwd then echo "incorrect userid used"
# If its entered incorrectly and not a valid ID then they will get this comment. Again, im guessing this part would be similar to te above option..... *) echo "not a valid ID";;
Ive managed to work out how the basic Case staements work, but to add a conditional statement based on the input, i just cant figure out. I have tried looking on google, and found some help but it doesnt really explain how i check the input against the /etc/passwd.
how do I get this regular expression to work in an if/else statement? This is just a little script for learning BASH. don't be too harsh.
This script will test if a certain number of files with 1-4 in their filename exist and print their filename. An error message will be printed if not.
# for i in `ls file[1-9]` do if [[ "$i" == *1-4 ]] ; then echo "This file, $i, ends in a number between 1-4" else echo "Error, this file, $i, does not end with a number between 1-4" fi done
I get this error. ./file_test.sh: 13: [[: not found
I was doing an exercise on Learning Perl, 3rd edition. (exercise chapter 10 btw) The problem asks to create a program that generates a random number and asks the user to guess. It should tell the user if the guess is lower or higher and exit if the user types either exit or quit. My code is the following:
What I want to achieve is, if I have following in my file: x y X z I should be able to find the pair, x Y and replace it with x a. So, basically I want to search for case sensitive 'x' but search and replace case insensitive 'y'. How should I do it? Can this be achieved with 'sed' command?
I'm trying to clear a bit of space in my overstuffed filing cabinet by scanning all my bank statements, credit card statements, insurance, important post etc. into my computer.
I've been looking for a very simple document management system, where I can record the category (bank statement etc.) date, comment, etc.
I don't want to make these accessible via the internet and I really don't want to hand them all to Mr. Google, via googledocs, because he already has enough info about me without reading my bank statements.
We are building our C++ project in Kdevelop IDE. Every time we run "Run Configure" from the "Build" menu, a file named "libtool" gets automatically generated. This file contains a statement as "ECHO="echo"".f we run "Automake", without modifying the "libtool" the system hangs and theputer needs to be restarted.Therefore every time we run "Run Configure" we need to include the line "echo="echo"" below the statement "ECHO="echo"" manually.I think a script can be written which does the above on its own.I am not a shell script programmer, I know the good tutorials for shell scripts are available on the net, but learning scripting only for this task would be time-consuming and painful.
I do 'mkisofs -iso-level 1 -o image John Smith.txt'. Only an example. When I mount image, ls outputs john_smi.txt. So it has shorten to 8.3 and translated ' ' into '_'. This is in accordance with the manual, although it doesn't say the conversion will be done.
Quote:
-iso-level level ......................... With all iso9660 levels from 1..3, all filenames are restricted to upper case letters, numbers and the underscore (_). ...........................
However, as it did not reject the file name, it should have converted it to all upper case, it seems to me. And -iso-level 2|3 does the same thing.
Code:
root@darkstar:~# mkisofs -iso-level 1 -o image John Smith.txt Total translation table size: 0 Total rockridge attributes bytes: 0 Total directory bytes: 0