[ask]gate date in different name file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [ask]gate date in different name file
# 1  
Old 07-02-2011
[ask]gate date in different name file

hlow all,
i have case with different name file tto filter name date only
example file
Code:
BDG.20110627.653212.txt
3GSMG.21.32.20110620.34112.3211.txt
MDN.000.234.123.20110619.2313.3.txt

output
Code:
20110627.txt
20110620.txt
20110619.txt

how can i filtering to get the date if they dinamic position Smilie
any idea for this...

thx for your advice
# 2  
Old 07-02-2011
Try this with GNU sed:

Code:
$ cat >testfile
BDG.20110627.653212.txt
3GSMG.21.32.20110620.34112.3211.txt
MDN.000.234.123.20110619.2313.3.txt
$ sed -r 's/.*\.(20[0-9]{6})\..*/\1.txt/' testfile
20110627.txt
20110620.txt
20110619.txt


Last edited by yazu; 07-02-2011 at 02:05 AM.. Reason: more robust
This User Gave Thanks to yazu For This Post:
# 3  
Old 07-02-2011
@yazu thx for your replay
but in case not include in file if I ls have thist
Code:
# ls
BDG.20110627.653212.txt
3GSMG.21.32.20110620.34112.3211.txt
MDN.000.234.123.20110619.2313.3.txt

so i want get file like this
Code:
#ls
20110627.txt
20110620.txt
20110619.txt

anyway have sed compile with
Code:
find -name *.txt*|sed -r 's/.*\.(20[0-9]{6})\..*/\

any advice????

Last edited by zvtral; 07-02-2011 at 02:30 AM..
# 4  
Old 07-04-2011
hlow there

any can help me about this case???
input
Code:
# ls
BDG.20110627.653212.txt
3GSMG.21.32.20110620.34112.3211.txt
MDN.000.234.123.20110619.2313.3.txt

output
Code:
#ls
20110627.txt
20110620.txt
20110619.txt

with awk

Last edited by zvtral; 07-04-2011 at 11:28 AM..
# 5  
Old 07-04-2011
Code:
ls | sed 's/.*\([0-9]\{8\}\).*/\1.txt/'

Code:
for i in *
do
mv $i $(echo $i | sed 's/.*\([0-9]\{8\}\).*/\1.txt/')
done

This User Gave Thanks to ctsgnb For This Post:
# 6  
Old 07-04-2011
Quote:
Originally Posted by ctsgnb
Code:
ls | sed 's/.*\([0-9]\{8\}\).*/\1.txt/'

Code:
for i in *
do
mv $i $(echo $i | sed 's/.*\([0-9]\{8\}\).*/\1.txt/')
done

wow its a great yhx men for helping meSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

2. UNIX for Dummies Questions & Answers

How to pick the latest file with date as one among the file name.( not exactly present date.)?

i have files like 1)20131112_abc_01.csv and 2)20131113_abc_01.csv and 3)20131113_abc_02.csv when i try to fetch the file in the next day. it shud pick the third file.. plz help me.. and i use `date +"%Y%m%d"` command to fetch..it fetches the current date... (2 Replies)
Discussion started by: applepie
2 Replies

3. Shell Programming and Scripting

finding date numeral from file and check the validity of date format

hi there I have file names in different format as below triss_20111117_fxcb.csv triss_fxcb_20111117.csv xpnl_hypo_reu_miplvdone_11172011.csv xpnl_hypo_reu_miplvdone_11-17-2011.csv xpnl_hypo_reu_miplvdone_20111117.csv xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Discussion started by: manas_ranjan
10 Replies

4. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

5. Linux

linux-gate - x86 - a few questions

I'm aware of the linux-gate VDSO used to implement the sysenter mechanism for system calls. On older kernels this was mapped to a static location in the address space of each process. Newer kernels allow this to be dynamically located (though I don't think it's used by any distribution yet). How... (0 Replies)
Discussion started by: G_Morgan
0 Replies
Login or Register to Ask a Question