|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
remove file extension
Hi ALL,
I'm new to this forum. Thanks and congrats to all for their great efforts building this site simply superb for all unix administrators. My requirement is to remove extensions of the files in the current directory. I'm doing it using below script which is working but i think it is very inefficient as i use lot of variables.I want to get done by avoiding usage of tempfile file and any other temp files being used. #!/usr/bin/bash ls -l |awk '{print $9}' >/list cat /list |while read line do echo $line >/tempfile first=`cut -f1 -d'.' /tempfile` echo $first >>/output.txt mv $line $first done Thanks Praveen RK |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Code:
ls -1 | sed 's/\(.*\)\..*/\1/' |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Perhaps this. Code:
for file in *
do
if [ -f $file ] ; then
# name without extension
name=${file%\.*}
echo ${name} >> output.txt
fi ;
done |
|
#4
|
||||
|
||||
|
You really dont need the -1 if you are going to pipe the output to some other command.
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
![]() |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thanks Lorcan for your quick reply. The command just displays the files without extension but how to add "mv" most efficiently as i need to rename the files?
Praveen RK |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Thanks vino, i got it done.
Lorcan, thanks and ignore my last msg. |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can i unzip .gz extension file? | J_ang | UNIX for Advanced & Expert Users | 9 | 07-11-2009 01:08 PM |
| How to get file extension | shirleyeow | Shell Programming and Scripting | 17 | 01-17-2008 07:40 AM |
| File System extension | xramm | Solaris | 4 | 09-20-2007 08:48 AM |
| Stripping out the extension of a file name | ramky79 | Shell Programming and Scripting | 2 | 12-27-2006 01:25 PM |
| default extension of file | rujupriya | UNIX for Dummies Questions & Answers | 2 | 05-17-2006 10:49 AM |
|
|