•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,555 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,483 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 3099 | Replies: 10
![]() |
filename=me.cpp
# If you use ksh or bash
filename=${filename%cpp}out
# if you use sh
filename=`echo $filename | sed -e s/cpp$/out/` Last edited by masijade : Oct 19th, 2007 at 2:36 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Good for you. Experiment a bit.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Give a better description of what it is you want to do. Have you even tried those things that were posted?
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Oct 2007
Posts: 13
Reputation:
Rep Power: 2
Solved Threads: 0
This is what I have from the example:
#!/bin/bash
#
# Replaces blanks with underscores in all the filenames
# of the current directory.
i=0
for filename in *
do
echo "$filename" | grep -q " "
if [ $? -eq 0 ]
then
fname=$filename
n=`echo $fname | sed -e "s/ /_/g"`
mv "$fname" "$n"
((i++1))
fi
done
echo "$i file(s), done."
exit 0
#!/bin/bash
#
# Replaces blanks with underscores in all the filenames
# of the current directory.
i=0
for filename in *
do
echo "$filename" | grep -q " "
if [ $? -eq 0 ]
then
fname=$filename
n=`echo $fname | sed -e "s/ /_/g"`
mv "$fname" "$n"
((i++1))
fi
done
echo "$i file(s), done."
exit 0
Well, it's bash, so as I said in my first post
However, .cpp to .out usually means you want to compile the files, which has nothing to do with simply renaming them like this.
for filename in *.cpp
do
mv "${filename}" "${filename%cpp}out"
doneHowever, .cpp to .out usually means you want to compile the files, which has nothing to do with simply renaming them like this.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Regular Expressions (VB.NET)
- Parsing a log file using regular expressions (C#)
- Regular Expressions (C#)
- Regular Expressions (Computer Science and Software Design)
- Regular Expressions (C#)
- Regular expression (Perl)
- mod_rewrite: help with regular expressions (Linux Servers and Apache)
- matching regular expressions (Java)
Other Threads in the Shell Scripting Forum
- Previous Thread: set ulimit inside of shell script
- Next Thread: Desparate Need of Help!



Linear Mode