Lo all,
How can i create a simple bash script to cut out a small part (eg. a word) of a name of a file, the same word on several files?
In more detail, i have several files (of same extension), which start with
name_foo.txt
name_blah.txt
name_fart.txt
or sometimes
something [lol].zip
jack [lol].zip
I'm assuming the program has to ask me for the common word, search a folder, display the files with the common word, and ask me to delete it...
I've managed to write up 2 functions to get the location and search for file names with that word respectively, but can't quite figure out how to delete that word from the file names...
Code:
#! /bin/bash
# This is a trap, to catch signals
# particularely ctrl^c
trap 'echo "Force Quit."; exit 1' 2
# Ask for the directory
function askForDir
{
# Ask user for the location of the file
echo -n "Location of Directory (leave empty for current): "
read myLocation
# If no input then take default source location
if [ "$myLocation" = "" ]; then
pwd > location
myLocation="$location"
fi
echo "Location: $myLocation"
}
# Search for the word you want.
function searchForWord
{
echo -n "Enter Word: "
read myWord
echo "Files with '$myWord' are: "
ls $myLocation | grep $myWord
read temp
}
askForDir
searchForWord
Note: default source location section doesn't work atm...
EDIT: heh.. apparently it *does* work =)
Thanks