![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help renaming files | bbbngowc | UNIX for Dummies Questions & Answers | 5 | 04-23-2008 02:08 PM |
| renaming files | jxh461 | UNIX for Dummies Questions & Answers | 1 | 02-04-2008 09:32 PM |
| Renaming files | Tygoon | UNIX for Dummies Questions & Answers | 7 | 01-06-2008 10:59 PM |
| renaming files | systemsb | UNIX for Dummies Questions & Answers | 3 | 05-25-2006 12:56 AM |
| renaming files | raguramtgr | UNIX for Dummies Questions & Answers | 4 | 09-21-2004 10:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Renaming Files
Hi Alll,
I have a script that we use on the servers to change the name of files that have spaces in the name: #!/bin/tcsh set n = 0 foreach f ( * ) echo $f | grep " " if ( $? == 0 ) then mv "$f" `echo $f | sed -e "s/ /_/g"` @ n += 1 endif end echo $n changed I need to write a script which renames all ascii text files in the current directory by adding a number to their names before the “extension”. for example <name>_a<number>.<”extension”> for example creditA, creditB, creditC, debitA get changed to creditA1, creditB2, creditC3, debitA4. That is for changing all the files on the server to have a number in them...... I have this code which is wrong #!/bin/tcsh set n = 0 set m = 0 foreach f ( * ) file $f | grep "ascii text" if ( $? == 0 ) then mv "$f" `echo $f"_a"$m` @ n += 1 @ m += 1 endif end I need to divide the $f into two parts one part before the . and the other part after the . but I dont know how. Any help Any help... Last edited by abch624; 03-19-2008 at 04:20 PM.. Reason: More Info |
|
||||
|
Hi
try this...Hope this solves your problem.. #!/bin/ksh ctr=1 for i in * do var1=`file $i |awk '{printf "%s\n",$3}'` if [ $var1 = "text" ]; then filename=`ls $i | cut -f1 -d "."` \\the filename before the dot \\ ext=`ls $i |awk -F "." '{printf "%s\n",$2}'` \\filename after the dot\\ mv $i $filename$ctr.$ext ctr=`expr $ctr + 1` fi done ~ Thanks.. Antony Cecil |
|
|||||
|
Thread closed. Duplicate of Renaming Files
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|