![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Searching all files that contain pattern | ravi.sadani19 | Shell Programming and Scripting | 4 | 11-29-2008 06:52 PM |
| searching files inside directory | kylethesir | UNIX for Dummies Questions & Answers | 4 | 06-06-2008 01:44 AM |
| Searching for files with certain string pattern | intrigue | UNIX for Dummies Questions & Answers | 1 | 02-28-2008 05:28 PM |
| Pattern searching pattern in c files | murthybptl | Shell Programming and Scripting | 6 | 11-17-2007 09:15 AM |
| Regarding Searching Pattern | sbasetty | Shell Programming and Scripting | 2 | 09-29-2006 05:49 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Pattern searching inside Variable - not looking at files
Hi,
I've searched this site and not found this already, so if I missed on my search, sorry. I need to pass in a variable to a script, where the first three characters of that variable represent a calendar quarter, and the last 2 characters are the year. I.E. Q0105 for Q1, Q0205 for Q2, and so on. How to do this is not the question. Inside the script, I need to pattern match on the first three characters to determine what quarter it is (technically I could match on the 3rd char only but it's easier to read and understand if I do all three - but not stuck on that). The reason is I need to populate three other variables based on the quarter. The other variables represent the months, so for Q0105, I need to make M0105, M0205, M0305. For Q0405 I need to make M1005, M1105, M1205. So, how do I read just the first three chars that are inside the input variable, to match it up to a quarter? Thanks! ![]() |
|
||||
|
Of course, as soon as I post this, the guy here at work that I asked, who had no idea, came up with something that worked.....
INPUT_VAL=$1 if [[ ${INPUT_VAL%${INPUT_VAL##Q01}} = "Q01" ]]; then print "Quarter is 1"else if [[ ${INPUT_VAL%${INPUT_VAL##Q02}} = "Q02" ]]; thenfiprint "Quarter is 2"else Last edited by Rediranch; 06-06-2005 at 05:00 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|