file name transformation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file name transformation
# 1  
Old 05-22-2008
file name transformation

I've got a multitude of text data files that carry exactly the same kind of data. Unfortunately some of them have a different filename format

some are: 'category'_'month'-'year'_act.txt

an example being: daf_Apr-1961_act.txt



and some are: 'category'_ 'year'-'month'_act.txt

an example being: daf_1961-04_act.txt


any suggestions for transforming the former to the latter?
# 2  
Old 05-22-2008
Shell script is the only option here.Try using case.Following can be tried..

Code:
case $name in
          01 ) $month=Jan
              ;;
          02 ) $month=Feb
              ;;
             ....... so on
      esac
  done

# 3  
Old 05-22-2008
Quote:
Originally Posted by nua7
Shell script is the only option here.Try using case.Following can be tried..

Code:
case $name in
          01 ) $month=Jan
              ;;
          02 ) $month=Feb
              ;;
             ....... so on
      esac
  done

Thanks Nua7

What about rearranging the sequence of the file title = swapping the month and the year around. I was more concerned if that was possible.
# 4  
Old 05-22-2008
Yes that should be possible, Split the file name in variables as $category, $date, $month and rearrange as you wish..

Thanks!
nua7
# 5  
Old 05-22-2008
Something like this?

Code:
$ echo "daf_1961-04_act.txt"|sed 's/\(.*_\)\(.*\)-\(.*\)\(_.*\)/\1\3-\2\4/'
$ daf_04-1961_act.txt


$ echo "daf_Apr-1961_act.txt"|sed 's/\(.*_\)\(.*\)-\(.*\)\(_.*\)/\1\3-\2\4/'
$ daf_1961-Apr_act.txt

Regards
# 6  
Old 05-22-2008
This is Fantastic Franklin52..!!

vrms , that should work..
# 7  
Old 05-22-2008
Quote:
Originally Posted by Franklin52
Something like this?

Code:
$ echo "daf_1961-04_act.txt"|sed 's/\(.*_\)\(.*\)-\(.*\)\(_.*\)/\1\3-\2\4/'
$ daf_04-1961_act.txt


$ echo "daf_Apr-1961_act.txt"|sed 's/\(.*_\)\(.*\)-\(.*\)\(_.*\)/\1\3-\2\4/'
$ daf_1961-Apr_act.txt

Regards
Thanks guys this is great stuff!!

However, this might be me being very dumb, but is there a way of 'saving' this new file name to the original. And could this then be automated to do more than one file at a time. Sorry I'm a bit new to this.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Data transformation

I do have an input text file of the following format with 1000's of lines input file: 3386(11:11,Ani:0,Bri:1,ch:1,Jwe:0,Jor:0,LP:0,Lo:0,NS:1,al:1,bo:0,boy:0,bru:0,sh:0,cor:1,dum:0,ery:0,mac:0,mic:0)... (3 Replies)
Discussion started by: Kanja
3 Replies

2. Shell Programming and Scripting

Row to Column transformation

Hello Experts, I need to transform rows into column using awk. I tried few things but failed to obtain desired output, as I'm fairly new to awk. i/p file 100, READ, 12 100, WRITE, 8 100, SEEK, 1 142, READ, 2 142, WRITE, 34 142, SEEK, 3 O/p Needed PROC_ID 100 142 READ 12 ... (2 Replies)
Discussion started by: sybadm
2 Replies

3. UNIX for Dummies Questions & Answers

file transformation using fixed width file

Hi Gurus! I need to make some file transformations. Please help. This is my input file. It has four columns with fixed width. 1 aaa bbbb cccc 2 eee dddd jjjj 3 fff gggg jjjj 4 hhh iiii cccc 5 kkk llll cccc 6 mmm nnnn oooo 7 ppp qqqq xxxx 8 rrr ... (1 Reply)
Discussion started by: kokoro
1 Replies

4. Shell Programming and Scripting

Clipboard transformation scripting

Hello all, I've done a bit of clipboard transformation scripting using xclip before, piping contents with " xclip -o -selection clipboard " to grep, sed, awk, then back into the clipboard with " xclip -i -selection clipboard " ... but I am not a fantastically skilled user of either of the three... (4 Replies)
Discussion started by: la2ar0
4 Replies

5. Shell Programming and Scripting

XML file transformation

Hi all, I have to transform a XML file like this: <?xml version="1.0"?> <vocabulary> <voc_id>102</voc_id> <name>Vocabulary Name</name> <description>Voc description</description> <relations>3</relations> <hierarchy>5</hierarchy> <word> <word_id>1</word_id> ... (1 Reply)
Discussion started by: aLittleBeat
1 Replies

6. UNIX for Advanced & Expert Users

Need help in xslt transformation

Hi I have one input xml file <param name="EXTR_COL" valueDesc="AUTHD_RFLL" value="rx.AUTHD_RFLL" /> There is a mapping parameters in Database. if EXTR_COL is present in input XML then it is mapped to fieldlist. so the o/p XML looks like <fieldlist> <datasource... (1 Reply)
Discussion started by: srinu19
1 Replies

7. Shell Programming and Scripting

xslt transformation through Unix

Hi .. I have one input XML and I want to convert into another XML using parameter mapping through Database through Unix shell script. But I dont have idea how to do that. And how can I create xsl sheet if mapping is through database tables. Please help me on this. (1 Reply)
Discussion started by: srinu19
1 Replies

8. Shell Programming and Scripting

File transformation - what is most efficient method

I've done quite a bit of searching on this but cannot seem to find exactly what I'm looking for. Say I have a | delimited input file with 6 columns and I need to change the value of a few columns and create an output file. With my limited knowledge I can do this with many lines of code but want... (5 Replies)
Discussion started by: 1superdork
5 Replies

9. UNIX for Dummies Questions & Answers

Transformation capital letter

:confused: Hye everybody i would like to know if exist a internet site where i can founs some interesting shell script very usefull I need to transform hundreds names of files escribed in CAPITAL letter in minuscule letter do oyu know a mean o do that that thanks to a script or a shell... (1 Reply)
Discussion started by: Dark Angel
1 Replies
Login or Register to Ask a Question