Help - Search - Members - Calendar
Full Version: BASH to strip underscores?
Linuxhelp > Support > Programming in Linux
Termina
I have several pictures in a directory. They all look like: first_last.jpeg

I'd like a simple bash script to rename any that have an unscore, so they all look like: firstlast.jpeg

Thanks
Hemant
do something like this:
CODE
$ ls|sed -e 's/_//g'
Hemant
Ohh...you need script to rename files...sorry abt that:
CODE
for x in `ls`; do y=`echo $x|sed 's/\_//'`; mv $x $y; done


But this script will only remove only one underscore from filenames so beware!!

PS: or run it twice to remove more than one underscores!! In each run..it will remove one underscore..
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.