file name transformation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file name transformation
# 15  
Old 05-23-2008
When I do the above on directory containing :

daf_2001-03_act.txt
daf_2001-04_act.txt

The content of the files are put on the screen as before.
When I do an ls I get the following files


daf_2001-03_act.txt daf_2001-03_act.txt~ daf_2001-04_act.txt daf_2001-04_act.txt~

As can see there are two new files with a ~ following them. But the filenames are the same.

Hmmm. This is a tough cookie isn't it!
# 16  
Old 05-23-2008
Those files look like temporary files created by a program.
If you want to exclude those files you can extend the grep command e.g.:

Code:
for file in `ls | grep ".*_....-.._.*[^~]$"`
do
  sed 's/\(.*_\)\(.*\)-\(.*\)\(_.*\)/mv & \1\3-\2\4/' "$file"
done

Regards
# 17  
Old 05-27-2008
MySQL Finally got it working

Firstly thanks to everyone who posted on this thread.
I've finally got it working correctly!!

The code I used is as follows:

Code:
for file in $(ls -1)
do
  newfile="$(echo $file | sed 's/\(.*_\)\(.*\)-\(.*\)\(_.*\)/\1\3-\2\4/')"
  mv $file $newfile
done

Smilie

Last edited by vrms; 05-27-2008 at 11:55 AM..
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