How to grep mix of numbers and systemdate?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grep mix of numbers and systemdate?
# 1  
Old 12-22-2008
Question How to grep mix of numbers and systemdate?

Hi Guys,

i'm beginner in UNIX commands, need some help on this simple question:
I need to make a shell script to move files to another directory,
the criterias are :
1. the range of 4 last digit of the file name is 0100-0199
2. move all files that processed daily (let's say today is 22Dec'08)

so if i have these processed files in my folder, those 3 files(BOLD) should be moved :

XMAS200811100100.txt
XMAS200811110100.txt
XMAS200812150105.txt
XMAS200812220100.txt
XMAS200812220200.txt
XMAS200812220199.txt
XMAS200812220177.txt

how to write a shell script to read that kind of format(mix of range numbers and system date) and move it to another folder? Smilie

Thanks a lott....
# 2  
Old 12-22-2008
Hammer & Screwdriver Some of the logic needed

I put my example to a file, and then used cat to show the output. The cat command is not really needed, you could pipe your ls output directly to the grep part of my example.

Code:
> cat file121
XMAS200811100100.txt
XMAS200811110100.txt
XMAS200812150105.txt
XMAS200812220100.txt
XMAS200812220200.txt
XMAS200812220199.txt
XMAS200812220177.txt
> today=`date "+%Y%m%d"`
> cat file121 | grep "XMAS${today}01[0-9][0-9].txt"
XMAS200812220100.txt
XMAS200812220199.txt
XMAS200812220177.txt

# 3  
Old 12-22-2008
to expand on the example above:

today=`date "+%Y%m%d"`
for i in `cat file121 | grep "XMAS${today}01[0-9][0-9].txt"`; do
mv $i <dest_directory>
done
Padow
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Grep for a line containing only 5 numbers

How would you grep for a line containing only 5 numbers? Something like this. 10 2 12 1 13 (4 Replies)
Discussion started by: cokedude
4 Replies

2. UNIX for Dummies Questions & Answers

Grep for a range of numbers?

I am trying to extract specific information from a large *.sam file (it's originally 28Gb). I want to extract all lines that are on chr3 somewhere in the range of 112,937,439-113,437,438. Here is a sample line from my file so you can get a feel for what each line looks like: seq.4 0 ... (8 Replies)
Discussion started by: genGirl23
8 Replies

3. Shell Programming and Scripting

grep for a range of numbers

Dear Friends, I want to know how to grep for the lines that has a number between given range(start and end). I have tried the following sed command. sed -n -e '/20030101011442/,/20030101035519/p' However this requires both start and end to be part of the content being grepped. However... (4 Replies)
Discussion started by: tamil.pamaran
4 Replies

4. UNIX for Dummies Questions & Answers

grep to get line numbers

I know if i use grep -n that the output will have the lines numbered but is there a way to grep the actually line number. so like this grep -n "one" /usr/dict/numbers 1:one 21:twenty-one 31:thirty-one 41:forty-one 51:fifty-one 61:sixty-one 71:seventy-one 81:eighty-one 91:ninety-one ... (1 Reply)
Discussion started by: alindner
1 Replies

5. UNIX Desktop Questions & Answers

grep numbers

Hi all, I am new to unix and struggling to do the below I have few lines in a xml <title>abc:1</title> <description>abc:2</description> <language>abc:3</language> Is it possible to extract only the entire word like abc:1 abc:2 abc:3 instead of the entire line into a new file . Kindly... (3 Replies)
Discussion started by: umapearl
3 Replies

6. UNIX for Dummies Questions & Answers

Using grep on a range of numbers

Hi im new to unix and need to find a way to grep the top 5 numbers in a file and put them into another file. For example my file looks like this abcdef 50000 abcdef 45000 abcdef 40000 abcdef 35000 abcdef 30000 abcdef 25000 abcdef 20000 abcdef 15000 abcdef 10000 and so on... How can... (1 Reply)
Discussion started by: ProgChick2oo9
1 Replies

7. Shell Programming and Scripting

Sed to grep only numbers in string

Hi, I would like to get only number in the following strings. var1="Type20" var2="type 3" var3="value 2" var4="Type 1 Datacenter Hall 2" I would like to extract output as 20 from var1 and 3 from var2,2 from var3 and 1 from var4. Appreciate any one help asap.. Regards, Aji (5 Replies)
Discussion started by: ajilesh
5 Replies

8. UNIX for Dummies Questions & Answers

grep numbers

Hello, I'm trying to grep for digits surrounded by non digits and I'm obviously misinformed. Could someone help me get this sorted out here is what I have that is not working grep -ho '\D(\{11\})\D' *.txt (5 Replies)
Discussion started by: mcgrailm
5 Replies

9. Shell Programming and Scripting

grep for non numbers

Hi, I want to find out whether a string contains non numbers and + and - example : Str="0005000A" - It contains A Str="0005000+" - No problem What I have done is , echo $Str | grep I will have to list out all non numeric characters... (6 Replies)
Discussion started by: shihabvk
6 Replies

10. Shell Programming and Scripting

grep numbers range

I want to grep a range of numbers in a log file. My log file looks like this: 20050807070609Z;blah blah That is a combination of yr,month,date,hours,minutes,seconds. I want to search in the log file events that happened between a particular time. like between 20050807070000 to 20050822070000... (1 Reply)
Discussion started by: azmathshaikh
1 Replies
Login or Register to Ask a Question