Programming :: Replace Spaces With Underscores In File Names?

Jan 11, 2011

I often get files with many spaces as part of their names. I would like to automatically replace these spaces with underscores, but otherwise not change the file name. Is there a way to do this task with just the bash shell?

View 4 Replies


ADVERTISEMENT

Programming :: Rename File Names : Replace Dots By Spaces, Keep The Extension?

Mar 28, 2011

I am trying to rename a lot of files but need to keep the extension :

the files are films names :

a.b.c.d.***.iso

the result should be replacing "." by spaces " "

this command :

for files in *.iso ; do mv "$files" `echo "$files" | tr '.' ' '`; done

put a space also before the extension iso ??

How can I rename files from

"a.b.c.d.iso" to "a b c d.iso"

View 5 Replies View Related

Programming :: Bash File Names With Spaces?

Jul 24, 2010

I have a laptop that I am in through SSH. The laptop does not have an Xwindow system so I am using the program fbi to open an image on my laptop screen from my SSH connection:

fbi -T 8 picture.jpg #this opens the image on the laptops tty8 terminal

I've found that making a for loop does not work with files that contain a space in the name. Something to due with a bug that they call a "feature" that stops the first variable at the first whitespace.

Using a "while" loop is not exactly what i require either seeing as I want to be able to view each image in the directory on screen and tag it accordingly, before it jumps off to the next image, and I'm not sure how to add a pause to a while loop.

How do I make a Bash script and loop Variables handle files like "files that contain spaces.jpg"

View 5 Replies View Related

Programming :: Handle Files With Spaces In Their Names In Bash?

Apr 1, 2011

*I'm using Ubuntu 10.10

My issue is I can't handle the files with spaces in their name, I've donde the below script to print each file found inside folder and subbfolders with "find".

I would like to "ls" to each file found with its complete path and with its basename too.

Code:
files=$(find . -type f)
for each in "$files"
do
ls -l "$each" # 1rst option I've tried to list with full path
ls -l "$(/bin/echo "$each")" # 2nd option I've tried to list with full path
ls -l "$(/bin/echo $(basename "$each"))" # 1nd option I've tried to list with it basename

[Code].....

How can I list "ls -l" in both cases (with full path and with basename) when there are files with spaces in their name?

View 6 Replies View Related

General :: Remove Spaces From Many File Names Under Cygwin?

Nov 22, 2010

I'm hoping that someone can help me, I need to remove spaces (not replace with underscores) from several thousand files on a system with cygwin.
Can I do this from the shell using rename or mv somehow?

View 4 Replies View Related

Programming :: Sed - Replace All Spaces At Beginning Of Line With The Number 1?

Jun 21, 2010

Does any one know what syntax i could use to allow me to replace all instances at the beginning of a line with ones.

Before :

Code:
----------------------------------------------------------------------
Logical device information
----------------------------------------------------------------------
Logical device number 0
Logical device name : RAID1Mirror
RAID level : 1
Status of logical device : Optimal

After

Code:
----------------------------------------------------------------------
Logical device information
----------------------------------------------------------------------
Logical device number 0
111Logical device name : RAID1Mirror
1111RAID level : 1
11111Status of logical device : Optimal

View 12 Replies View Related

Ubuntu :: Replace All Tab Stops In A Text File With 4 Spaces?

May 18, 2011

How can I make vi and nano such that when I press the tab key, it automatically replaces the tab with 4 spaces?

View 5 Replies View Related

Programming :: Underscores In Standard Functions, An Example Section From Cat.c Is Included

Sep 4, 2010

From cat.c in GNU coreutils:

Code:
void
usage (int status)
{
if (status != EXIT_SUCCESS)
fprintf (stderr, _("Try `%s --help' for more information.

[Code]...

I don't remember ever seeing this in any examples I've ever seen, so I'm sure I've never seen an explanation of this.

View 1 Replies View Related

General :: Shell - Rename A File From Something Without Spaces To Something Containing Spaces?

Jan 26, 2010

Is it possible, in Linux, to rename a file from something without spaces to something containing spaces? I know I can create directories and files with spaces by doing:

mkdir "new dir" and:

touch "new file.txt"

I want to rename files from:

imgp0882.jpg to something like:

20091231 1243 some topic.jpg

And how would it look in a shell script that uses parameters like:

for i in *.jpg do
rename "$i" "$somepath/$mydate $mytime $mytopic$extension"
?

I'm new to Linux (using PCLinuxOS 2009.2), coming from Windows, and I've written myself a little shell script to download files from my camera and then automatically rename them according to a date-and-topic pattern. As you can guess by now, I'm stuck on the bit about renaming. If you want to see my script, here's a copy. I'm not using jhead for this renaming because that only works with JPEG files but I want a single solution for any media format including videos.

View 2 Replies View Related

Ubuntu :: Tomboy Links For Folder Names With Spaces?

Oct 20, 2010

The title should be clear enough. I'm sure its bad practice, but I have loads of folder names with spaces in them. In the terminal I would use the backslash e.g. /home/me/D O C S/More DocumentsBut how do I get Tomboy to recognize the link?

View 1 Replies View Related

Programming :: Reading And Writing White Spaces To A File?

Dec 2, 2010

I am trying to read a file character wise and trying to write the same character to another file. In this process, I unable to read and write white spaces successfully to the new file. The script reads the white spaces but while writing the white space is lost. The section of the code, is given below. Please advice how can i read and retain the white space while writing to a new file.

Code:

if [ -s f_test.txt ] && [ -f f_test.txt ]; then
echo "File Exists !!"
while read -n1 char; do

[code]....

View 2 Replies View Related

General :: Replace Multiple Spaces By One Tab

Feb 2, 2011

Ive some textfiles which contains some colums seperated by a various number of spaces, but instead i need one single tab as a seperator.

View 5 Replies View Related

Ubuntu :: Video Thumnailer Not Working On Files With Spaces In Their Names?

May 15, 2011

ffmpegthumbnailer is not working on files with spaces in their names. If i rename the file with no spaces then it creates a thumbnail with no problem.

View 4 Replies View Related

Software :: Using Sed To Search And Replace Does Not Accept Spaces?

Feb 16, 2011

Back to the problem: I wrote a little bash script that people around here can run to search and replace strings in the current directory and all subdirectories. However, whenever there is a space in the new string (the one doing the replacing), I get this error:

Sed: -e expression #1, char 9: unterminated `s' command

My code looks like this:

Code:
find ./ -type f -not -name find_SNR.sh -exec sed -i 's/'$FIND_SNR_STR1/$FIND_SNR_STR2/'' {} ;

View 5 Replies View Related

Software :: Make Mcedit Not Replace Tabs With 8 Spaces?

Mar 17, 2010

How to make mcedit not replace tabs with 8 spaces?

View 2 Replies View Related

Programming :: Perl Find File And Then Replace String In File

Jul 28, 2009

I have script that I'm working on that updates a username in all the files that are called blah.inc for my framework. since i host a bunch of these web apps i need to do it to all of them. so I need to figure out how to update these files automagically with out me watching it to call vim every time. heres what I have so far

Code:

This finds the files but now i need to figure out how to do s/bob/fred/g on those files.

View 5 Replies View Related

Programming :: Read File Names In A Dir And Its Sub Dir In Perl?

Apr 22, 2010

I am writing a script that involves reading the content of a file present in a directory and/or its sub directory. I know readdir returns all the files & DIR names in a directory but how to check weather readdir is returning a file or a directory

View 2 Replies View Related

Programming :: Using File As Replace In Sed

Mar 1, 2011

I have a file, "outfile" what I wish to insert into a file called template where it finds "OVERRIDES". I am getting an error.

Code:

However I can do something like this and it works fine

Code:

I am guessing its because of the file size or multiple lines.

A sample of the outfile text is below

Code:

View 9 Replies View Related

Programming :: Bash File Names Different Than Openbox Trash

Feb 14, 2011

Im writing my first bash script. Its function is to move files to the trash can and write a log file in the same format that the system does to allow for file restoration. The problem is that in bash, everything works fine, but in the OpenBox window session, the files are named after the source directory, not the original name. Heres the script:

Code:
#!/bin/bash
# trash - Script to move file or folder to the trash can and create a log file
##### Functions #####
err_output () # Writes error message {
echo "$0: cannot stat `$1': No such file or directory"
echo "USAGE: $0 SOURCE DEST"
exit 1 } >&2

write_log_numbered ()
# Writes log entry for numbered files {
echo "[Trash Info]" > $HOME/.local/share/Trash/info/${FILE}.$max.trashinfo
echo "Path="$PWD >> $HOME/.local/share/Trash/info/${FILE}.$max.trashinfo
echo "DeletionDate="`date "+%Y-%m-%dT%H:%M:%S"` >> $HOME/.local/share/Trash/info/${FILE}.$max.trashinfo
}

write_log_unique () # Writes log entry for unique files {
echo "[Trash Info]" > $HOME/.local/share/Trash/info/${FILE}.trashinfo
echo "Path="$PWD >> $HOME/.local/share/Trash/info/${FILE}.trashinfo
echo "DeletionDate="`date "+%Y-%m-%dT%H:%M:%S"` >> $HOME/.local/share/Trash/info/${FILE}.trashinfo
} make_paths () # Makes necessary folders {
mkdir -p ~/.local/share/Trash
mkdir -p ~/.local/share/Trash/files
mkdir -p ~/.local/share/Trash/info
}

##### Main #####
make_paths
SOURCE="$1"
DEST=$(dirname ~/.local/share/Trash/files/filename)
[ -e "$SOURCE" ] || err_output "$SOURCE"
[ -d "$DEST" ] || err_output "$DEST"
FILE="$(basename "$SOURCE")"

if [ -e "${DEST}/${FILE}" ]; then
max=0 DIR="$(pwd)" cd "$DEST"
shopt -s nullglob for backup in "${FILE}."; do
nr=${backup#${FILE}.}
if [[ "$nr" =~ ^[0-9]+$ ]]; then
if (( nr>max )); then
max="$nr" fi
fi
done
cd "$DIR"
max=$(( max + 1 ))
write_log_numbered
mv -- "$SOURCE" "${DEST}/${FILE}.$max"
else
write_log_unique
mv -- "$SOURCE" "$DEST/${FILE}"
fi

So I run the script with the test file "Junk". In bash, it moves over and its named correctly.
Code:
~/.local/share/Trash/files$ ls
file file.1 Files Files.1 Junk
The log file is also named correctly

Code:
~/.local/share/Trash/info$ ls
file.1.trashinfo Files.1.trashinfo Files.trashinfo file.trashinfo Junk.trashinfo

But, when I go to view the trash can in the file manager in Openbox, the file is called "Testing" which is the name of the source directory. However, if I go to the trashcan via its full path (going to .local/, then share/) all the files are named correctly. Whats going on here? Is there some way to get the trash can to read the correct file name?

View 4 Replies View Related

Programming :: Replace A String Within A File ?

Feb 28, 2009

I've found some scripts that replaces a string in a file but it's not quite working for me.

And I'm trying to replace a tag in an xml file that looks like this

So I ran a command line like this perl -w -i -p -e "s/xmlns="'http://mydomain.org/replacethese.xsd'">/>/g" testfile.xml

And I get a error output

Search pattern not terminated at -e line 1.

Found the script from this blog [url]

View 7 Replies View Related

Programming :: Replace Part Of A File With Another?

Jan 8, 2010

There are a few things I was wondering about (using tools available in bash):How to insert a file at at the specified location of another.How to copy a portion of a file between two lines matching a regex to another file (and/or making sed only work between two lines matching a regex)How would you do this?

View 2 Replies View Related

Programming :: Using Key To Match Against Source.txt File To Add Xml Tags To Names In Perl

Jun 21, 2010

Using a list of names (over 4000 of them) painstakingly gleaned from the source file years ago for a database file, I want to match the names against the source file so that they can be updated with the tags <forename></forename> in the original source file.

I placed the list of names in @forenames (only posted a few of them here).

Perl script is:

I am able to get the name bracketed by the tags to appear on the console screen but don't know how to apply the output to the source file. Perhaps I need to do a match on the words then some kind of edit to surround the matching words with the xml tags? I'm a rank novice doing this as a labour of love for a friend.

View 3 Replies View Related

Programming :: Search And Replace In A Binary File?

Aug 11, 2010

i need to change a binary file, let's say to find and replace username:

find string: "/home/name/bla-bla-bla/ "
new string: "/home/anewname/bla-bla-bla/ "

i can do it, for example, in emacs (hexl-mode), but interesting in writing a script instead. it will be much more better for me if i could do it automatically. is there an analog of: sed 's/string1/string2/g' ? P.S. the best way is to recompile the binary files i have, but there are no sources available.

View 5 Replies View Related

Programming :: Replace 2nd Occurrence Of A String In A File - Sed Or Awk?

Apr 5, 2010

I know how to replace a particular instance (say 3rd one) of a word in a line using sed based on the sed one-liners. However I would like to replace a particular instance of a word in the entire file.

For example, here is a file:

Code:
John
Betty
Jack
Ron
Jack
Paul

So now I would like to replace the second instance of Jack (in red color) with "Rob" (for example). Not quite sure how to do that? I tried couple of things from here but they did not work.

View 10 Replies View Related

Programming :: Replace String In File Using Perl Or Sed

Jun 30, 2011

I have question about replacing a string in a file.

How can I replace the printerb's 10.1.1.1 to something else(10.1.1.2, for example) without replace printera's 10.1.1.1 accidentally?

I have tried perl -e -pi "s/10.1.1.1/10.1.1.2/g" /etc/hosts. but, perl replace both 10.1.1.1 to 10.1.1.2.

View 13 Replies View Related

Programming :: Script To Remove Single Quote That Begin And End File Names?

Aug 13, 2010

Made the following bash script named trimsquote:

Code:
#!/bin/bash
IFS=$'

[code]...

View 6 Replies View Related

Programming :: Replace The Default Path In A File(which Is A Script)?

Jul 19, 2010

I am trying to replace the default path in a file(which is a script)with the new path which I have get when the bash script runsThe code is

SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`
sed -i "s/$HomeDir/$SCRIPTPATH/g" <filename>

[code]....

View 4 Replies View Related

Programming :: Sed Doesn't Accept Variables To Replace In File

Mar 17, 2011

[code]...

The variables are clean and available in my script. No prob. $old is an IP-address of a server, $new as well. replacement-file is an xml-file (the ip-address to be changed is within an xml-tag). It should be trivial, but it isn't. I spent the last 3 hours reading about the problem, trying several different 'solutions' or workarounds. It should work, the '"' should take care that the variables get expanded, but whatever I try the old server IP isn't replaced.

View 7 Replies View Related

Programming :: Sed To Read The File And Replace And Insert The Pattern?

Jun 11, 2009

I want to read from the file and check for the pattern, if the line has some word like <string>: then string should be copied into buffer. Afterwards, I want to insert the same <string> with some word in the next line of the file. use sed command to perform the above mentioned operations?

View 2 Replies View Related

Programming :: Shell Script Replace A Line From A File?

Mar 4, 2010

I am beginner in this business of shell script and I have no idea how to do the following: I would like to replace the lines of my file that contains 'CFL=' by 'CFL=0.5'. Note that I want to replace the full line meaning

View 11 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved