![]() |
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 |
| Shell script to rename files with .1,.2,.3 ....ext respectively | satyajit007 | Shell Programming and Scripting | 4 | 02-06-2009 06:43 AM |
| How to Rename/Convert Files in Shell Scripting? | hanu_oracle | Shell Programming and Scripting | 11 | 10-21-2008 09:13 AM |
| Script to rename files | cpreovol | Shell Programming and Scripting | 3 | 04-01-2008 11:45 AM |
| Script to rename files | Dinkster | UNIX for Dummies Questions & Answers | 5 | 01-22-2008 08:55 AM |
| rename files using shell scripting | gfhgfnhhn | Shell Programming and Scripting | 4 | 07-04-2006 04:37 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi, i need a bit of help writting a tcsh script which renames all ascii text files in the current directory by adding a number to their names before the extension
so for example, a directory containing the files Hello.txt Hello.t Hello should have the following changes, Hello.txt should be converted to Hello_a1.txt Hello.t should be converted to Hello_a2.t Hello should be converted to Hello_a3 so it should put a _a and a number incrementing accordingly. ********************************************************* Im new to tcsh scripting, though i tried implementing it, and this is where i get to. #!/bin/tcsh set n = 1 foreach f ( * ) echo file $f == ascii if ( $? == 0 ) then mv "$f:r" "$f:r"_a$n @ n += 1 endif end echo $n changed I am aware that some parts are incorrect, and that I might be missing something, thats where i need help. thanks. |
|
|||||
|
You know you should not use (t)csh for scripting
![]() But if you insist you may try this: Code:
#!/bin/tcsh
set n = 0
foreach f ( * )
set _type = `file "$f"`
switch ( "$_type" )
case *ASCII*:
@ n ++
switch ( "$f" )
case *.*:
mv -- "$f" "$f:r"_a"$n"."$f:e"
continue
breaksw
endsw
mv -- "$f" "$f"_a"$n"
breaksw
endsw
end
echo "$n file(s) changed."
|
|
|||||
|
[t]csh is not recommended for scripting:
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|