use metacharacters to extract date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use metacharacters to extract date
# 1  
Old 06-16-2009
use metacharacters to extract date

If I have a filename as
filename.txt.20090807
and I use
for FILE in `find . -name "filename*" -type f`
do
my_time=${FILE#./filename.txt.}
I get my output as 20090807
However if my filename is
filename.Y20090807.txt
Is there a way I can use metacharacters in my variable
my_time=${FILE#./filename.????????????????????}
to get the date 20090807
# 2  
Old 06-16-2009
Hammer & Screwdriver Would something like this help?

Code:
> echo filename.Y20090807.txt
filename.Y20090807.txt

> echo filename.Y20090807.txt | tr -d "[:alpha:]"
.20090807.

> echo filename.Y20090807.txt | tr -d "[:alpha:]" | tr -d "[:punct:]"
20090807

# 3  
Old 06-16-2009
Can i use your code inside my variable

my_time=${FILE#./filename.txt.}

or else my loop wont work
# 4  
Old 06-16-2009
Hammer & Screwdriver It can be used, although unsure what you are really trying to do

Code:
> mytime=`echo filename.Y20090807.txt | tr -d "[:alpha:]" | tr -d "[:punct:]"`

and then to verify that I stored correctly into the variable
Code:
> echo $mytime
20090807

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

2. Shell Programming and Scripting

metacharacters separation

I have prepared a script to submit a string in a txt file. However there are somethings that I have to check before submitting the string in the txt file. One of those checks is to determine whether the string entered contains any metacharacters. I have tried sth like; echo "string" | grep -v ... (3 Replies)
Discussion started by: ozum
3 Replies

3. UNIX for Dummies Questions & Answers

The ll command + metacharacters

Hello. I am learning how to use Unix through an online course. Unfortunately the text that we use isn't very good, so I could use some help with a pretty basic question. Use metacharacters and the ll command to list all filenames under the datafiles directory that contain a dot "." with the... (2 Replies)
Discussion started by: feverdream
2 Replies

4. Shell Programming and Scripting

Metacharacters analysis

:confused:Hi , Can someone please advise what is the meaning of metacharacters in below code? a_PROCESS=${0##*/} a_DPFX=${a_PROCESS%.*} a_LPFX="a_DPFX : $$ : " a_UPFX="Usage: $a_PROCESS" Regards, gehlnar (3 Replies)
Discussion started by: gehlnar
3 Replies

5. Shell Programming and Scripting

extract date

I run few command from c shell script and after this i want to check the status. I write the following code and it give the error message like "Variable Syntax". Here is my code: #/ !/bin/csh -f rm -f <filename> if ($? != 0) then echo " command does not executed successfully!" end... (3 Replies)
Discussion started by: skumar11
3 Replies

6. UNIX for Dummies Questions & Answers

Metacharacters

I want to display an asterisk to the screen as part of a string. I know how to use the Backslash to escape it's value. But how do I display it without showing the Backslash? (1 Reply)
Discussion started by: regencyabs
1 Replies

7. Shell Programming and Scripting

Using metacharacters in loops

Is there a way to use metacharacters in a loop or in an if. I want to allow a user to enter Y, y, Yes, yes, Yah, etc... in a loop I tried: read response while *" ] do........ and while *" ] do ......... this works for grep or egrep but not in loops Why?????? (4 Replies)
Discussion started by: jrdnoland1
4 Replies
Login or Register to Ask a Question