Programming :: Bash - Test If First 2 Characters In A Filename Are Numbers?
Oct 21, 2010
I have a directory with files like this:
Code:
And what I'd like is to have the files renamed like this:
Code:
How could I code it so that it removes the numerical part of the filename (at the beginning), even with different patterns (like the 01 - artist vs the 01-artist)?
View 8 Replies
ADVERTISEMENT
Aug 19, 2010
Enterprise Linux 4 (2.6.9-78 kernel)...rename not working! Need to insert "_T" at the end of every file in a directory, just before the ".extension"
I have tried sed substitution with no success (because I do not know the codes and effects of anchoring well enough).
An example filename:
My failed tests:
Code:
Code:
Code:
Code:
View 9 Replies
View Related
Feb 13, 2011
I am using Debian Lenny 5.0.3 with a stock 2.6.26-2-amd64 kernel, and have a ~/Documents/HTMLS directory of 273.2MB (21590 files, 1063 sub-folders) which according to konqueror shows 1130 items - 572 files (60.8MB Total) - 558 folders, these were created by 'Save Page As' in Iceweasel 3.5.11. I am trying to copy the contents of this directory to a similar directory on a 2GB USB thumbdrive /dev/sdb1 which was partitioned and formatted as fat32 by Qparted. Problem is that the copying ceases after about 6 files transfer. I found that (as I am sure you know) the named.html files come with a matching named_files folder, and often there are what appear to be invalid characters such as '*','?',and ':' in the filenames in said named_files folders.
After exhaustive googling [I know we all say that] I found an instruction:
Code:
pax -rw -s '/[*?:]/_/gp' stuff /fat32/partition
that changes the name of the files, replacing said characters with '_', but whilst I can get pax from my repos, I really don't want to 'archive' the files - since I understand that pax was created to bridge a war between tar and cpio - because I want to be able to read the html files on an old (not connected to the Internet) WinXP tablet. So, I believe that I need to create a script, that scans all the filenames, greps and seds to replace said 'unacceptable' characters. I am assuming that Firefox on the Tablet PC will be able to open the htmls if I can get them onto the thumb drive. Are there any other known characters in filenames that M$ file systems can't handle?
View 1 Replies
View Related
Jan 9, 2010
I would like to get the filename (without extension) and the extension separately. The best solution I found so far is:
Let FILE="thefilenameofsomefilesfor_instance.txt"
Code:
NAME=`echo "$FILE" | cut -d'.' -f1`
EXTENSION=`echo "$FILE" | cut -d'.' -f2`
I think it would be better to count the len and remove 3 chars to right to get the extension, but it can be macintosh filenames with have 4 chars for extensions.
View 5 Replies
View Related
Jan 15, 2010
I have over 50 files names with spaces in them.
I'm trying to use a for loop as such:
However, when I print the $filename in the script, the script prints out parts of the filename because of the spaces in the file name.
For example, say the file name was Star Quest.php
When the script executes one $filename would be Star and another Quest.php.
How could I account for this? Something like $'filename'
View 13 Replies
View Related
Feb 2, 2010
For eg: $NUMBEROFPASSES=6.19 to round up I use NUMBEROFPASSES=$(printf %.0f $NUMBEROFPASSES) What I need to do is round up from eg: 6.10 to be 7 and if lower than 6.10 round down to 6
View 5 Replies
View Related
Mar 27, 2011
I'm learning shell scripting using bash and I want to generate 4 floating point number with 5 decimal places and write them to a file and a variable. I've done all this except the $RAMDOM enviroment variable does not generate a float number but a integrer.
[code]...
View 4 Replies
View Related
May 25, 2010
I have lines in some files that look exactly as below, and the line numbers they occur in are always the same. (Lines 136-139)
W 0.00000000 0.00000000 2.00000000
W 0.50000000 0.50000000 2.50000000
W 0.00000000 0.00000000 3.00000000
[code]...
View 1 Replies
View Related
Oct 3, 2009
i have lots of files with dots insde file name for example:
document.1.is.bigger.doc
resume.version12.doc
10.photo.www.cnn.com.jpg
i want to rename all files in that directory to be the same (with same extention) but convert dots to underscore "_"
how can i do that on bash script / php.
View 6 Replies
View Related
Apr 28, 2010
I just need to perform a simple operation of subtracting two numbers - that aren't whole numbers, i.e 200.56 - 67.24attempting to use expr i merely get "expr: non-numeric argument"
View 3 Replies
View Related
Apr 15, 2010
I created a file holding all the md5 values of my files to find duplicates as follows: find /mnt -type f -print0 | xargs -0 md5sum >> ~/home.md5
I then tried to find duplicates and do ls -l on the result in such way: cat ~/home.md5 | awk '{print $1}' | sort | uniq -c | sort -nr | awk '{print $2}' | head -n 10 > ~/top10.md5
Now I attempted to do an ls -l on the files using the command: for i in `cat ~/top10.md5`;do grep $i ~/home.md5 | while read checksum path; do echo "`echo $(printf '%q' "${path}")`" | xargs ls -l; done; done
This works well on most files, however it does not work when filenames have special letters in them that gets escaped such letters with accent etc. These become for examle 303.
Are there any ways I can use the escaped 303 strings with path names, or any better way I can do this?
View 2 Replies
View Related
Jan 28, 2010
I am fairly new to bash scripting, and I am trying to test a variable against a number range (1-3). This is what I have used so far: The user enters a value, then
while [ "$PROV" != "1" ] && [ "$PROV" != "2" ] && [ "$PROV" != "3" ] && [ $COUNTER -lt 4 ] || [ -z "$PROV" ] && [ $COUNTER -lt 4 ]; do
clear
echo
[code]....
Is there a cleaner way to do this? Something like:
while [ "$PROV" != "1-3" ]&& [ $COUNTER -lt 4 ] || [ -z "$PROV" ] && [ $COUNTER -lt 4 ]; do
View 3 Replies
View Related
Jan 26, 2011
I'm having issue when trying to change a line in a file
[Code]....
View 1 Replies
View Related
Jun 6, 2010
I have downloaded torrent from some chinese tracker. It has ???? and some other symbol charaters in directory name. How to delete that file and directory?
View 5 Replies
View Related
Apr 8, 2009
I look after a server which accepts automatic overnight PASV FTP uploads from remote clients. When the uploads are complete, my Bash script copies the files to another location. The problem is, my script needs to be a bit smarter when it comes to detecting active FTP sessions.
I was using:
Code:
netstat -n | grep ":21 " | grep ESTABLISHED
to test if there were active sessions, but came unstuck when a local user left an unrelated FTP session active. The result - my script hung around all night thinking there was an active upload from a remote client. My server is behind a firewall, so remote clients all show an internal (NAT) address,so I can't differentiate by source IP address.I can't install LSOF or FUSER for security reasons. Is there a way I can test for active FTP sessions from specific users? I am running Red Hat Enterprise Linux Server release 5.2 (Tikanga).
View 7 Replies
View Related
Aug 29, 2010
Trying to create a small script that will read user's input, test if user entered some input and if not display some message or display a text using user's input.
The script is the following but i get an error saying "[: 6: =: argument expected"
View 12 Replies
View Related
Dec 9, 2009
In previous versions of Fedora I was able to do Ctrl + Shift + U, enter the Unicode number - i.e., 20ac, press Enter and get a euro character. In Fedora 12 I do not have that feature. My language is US English.
View 5 Replies
View Related
Apr 4, 2011
am writing a small search program for my class. I have decided to use indexing for my program. Ive researched online about indexing and how search engines do it. If im gonno do that I need to create inverted files to associate files to numbers ( numbers being the index of my paths ) . Now I was wondering what would be the best way to create an inverted file ? I was going to create sql tables using mysql api in C but then again there is no array data type or vectors to store few numbers in a single column in mysql and it is not advised to use Enum or SET
View 14 Replies
View Related
Nov 18, 2009
How can we convert a dynamic library (filename.so) to a static library (filename.a) using gnu gcc . Can we get a static library form a dynamic library . I saw a few post in which the conversion form a static library to a dynamic library is mentioned but, unfortunately, not the other way.
View 4 Replies
View Related
Nov 18, 2010
What I have done wrong with my escaping here:
Code:
The original filename is:
Code:
View 4 Replies
View Related
Jun 25, 2015
I am trying to create scripts to move files over from one directory to an ftp server and there is this one file with spaces that bash is see each word as being a file, here is the variable i am trying to use:
Code: Select allLOCL = '/mnt/cifs/"File name with spaces"/'
cd $LOCL
ls -l
View 3 Replies
View Related
Jan 30, 2011
I was wondering if anyone knows how to do this in Bash:
I have quite a few music files which have names like this:
All my music is named "ARTIST - SONGNAME.EXTENTION"
I have been looking for a program or bash script that would fix this automatically, but I can't find anything that will do this. a script laying around?
Tried pyRenamer, and it does a lot of things, except this...
View 2 Replies
View Related
Nov 16, 2010
Our assignment is to take in two numbers and add them. While the inputs will always be numbers, we are to inform the user if they are doing it wrong. My code:
[Code]....
The code worked fine before I tried to idiot-proof it. I'll probably end up nesting the if statements checking if the first two inputs are not null, but I'm more annoyed at why the script isn't working.
View 3 Replies
View Related
Mar 18, 2011
I'm making an bash script.
As input you can input different numbers from 1 to 3.
Depending from the input a text shows up.
View 2 Replies
View Related
Sep 28, 2009
as a result of a find command, i have
852065 72: /bin/gunzip
852065 72: /bin/gzip
852065 72: /bin/zcat
(the first column is inode number and the second is size if you're curious)
I want to be able to format it in a way such that:
852065 72:
/bin/gunzip
/bin/gzip
/bin/zcat
I know I can get the bottom half using awk- but I can't figure out how to extract the first set of numbers and get them to appear only once
View 9 Replies
View Related
Nov 4, 2010
I have to read a couple of numbers from a random.txt file. In this .txt file there are random numbers. They are separated by a space. Example if you opened test.txt:
test.txt :1 6 1 3 6 8 10 2 4
I would like to read those numbers using CAT and store them into an array:
numlen=${#num[*]} - (must be like this because it is a part of a larger program)
View 5 Replies
View Related
Jan 23, 2011
$ uname -a
Linux a 2.6.35.10-74.fc14.i686.PAE #1 SMP Thu Dec 23 16:10:47 UTC 2010 i686 i686 i386 GNU/Linux
$ lsb_release -a
LSB Version: :core-4.0-ia32:core-4.0-noarch
[Code].....
How can I set a pattern that will output a filename equal to the original filename? E.g.
something.mp3 → something.ogg
And why isn't this implemented in SoundConverter?
PS: {Filename} doesn't work.
View 1 Replies
View Related
Apr 17, 2011
After writing a new prompt for Bash, I noticed that one character of my commands were being lost when it wrapped to the new line. Here is an image of the example (I typed 1234567890 over and over):
Here is my $PS1
PS1="
[[e[0;90m]d [e[0m]] [[e[0;90m]$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, $(/usr/bin/du -sh | cut -f1)[e[0m]
[[e[0;36m]#[e[0m]] [e[0;95m]u[e[0;90m]@[e[1;92m]h[e[0m]: [e[1;34m]w [e[1;30m]$[e[0m] "
What have I done wrong?
View 1 Replies
View Related
Feb 20, 2010
Say you wanted to write a bash script for "hello world" but the characters were shifted up or down by one.
How would one go about this?
Example:
Code:
Code:
View 5 Replies
View Related
Dec 18, 2010
I want to test whether or not my phone is connected from bash. I'm finding lots of information about /dev/rfcomm0, but that's not on my system (Ubuntu 10.04). The device pairs just fine, and I can connect with gammu just fine, and I have the device address ("00:1F:5D:37:17:FB").I just need something I can put in a bash script to say "Is this connected or not" akin to testing for a file's existence:
Code:
if [ -f /home/steven/arbitrary filename ]
then
[code]....
View 2 Replies
View Related