Bash Script - Removing Year and Text from File Name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script - Removing Year and Text from File Name
# 1  
Old 05-09-2009
Bash Script - Removing Year and Text from File Name

Hi,

I have files with names in the following naming pattern,

HTML Code:
Name.of.movie[2008]moretext-moretext.mov
or

HTML Code:
Name of movie[2008]moretext-moretext.mov
And I would like to delete the [year] and moretext-moretext leaving just the Name of movie.

The Name of movie will always be different and the year will be any year. Is this possible? Smilie


Thanks!
# 2  
Old 05-09-2009
you recently have a similar thread on this issue. what have you tried so far?
# 3  
Old 05-09-2009
Code:
name="Name of movie[2008]moretext-moretext.mov"
newname=${name%%\[*}.mov

# 4  
Old 05-09-2009
In the same time we can use the parameter expansion for file extension.
Code:
name="Name of movie[2008]moretext-moretext.mov"
echo ${name%%\[*}.${name##*.}

# 5  
Old 05-11-2009
Code:
echo "Name of movie[2008]moretext-moretext.mov" | sed 's/\[.*\./\./'
echo "Name.of.movie[2008]moretext-moretext.mov" | sed 's/\[.*\./\./'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH script to read external file to perform text replacements?

Hi all, I have a moderate size (300 lines) BASH Shell script that performs various tasks on different source reports (CSV files). One of the tasks that it performs, is to use SED to replace 'non-conforming' titles with conformant ones. For example "How to format a RAW Report" needs to become... (3 Replies)
Discussion started by: richardsantink
3 Replies

2. Shell Programming and Scripting

Bash script to replace text file from a lookup file

Hi. I need assistance with the replacing of text into a specific file via a bash script. My bash script, once run, currently provides a menu of computer names to choose.The script copies onto my system various files, depending what computer was selected in the menu.This is working OK. Now, I... (1 Reply)
Discussion started by: jonesn2000
1 Replies

3. Shell Programming and Scripting

Bash script - printing range of lines from text file

I'm working on a new exercise that calls for a script that will take in two arguments on the command line (representing the range of line numbers) and will subsequently print those lines from a a specified file. Command line would look like this: ./lines_script.bash 5 15 <file.txt. The script would... (8 Replies)
Discussion started by: ksmarine1980
8 Replies

4. Shell Programming and Scripting

Bash script help - removing certain rows from .csv file

Hello Everyone, I am trying to find a way to take a .csv file with 7 columns and a ton of rows (over 600,000) and remove the entire row if the cell in forth column is blank. Just to give you a little background on why I am doing this (just in case there is an easier way), I am pulling... (3 Replies)
Discussion started by: MrTuxor
3 Replies

5. Shell Programming and Scripting

bash script removing files except last one created

Hello there, can anyone please help to write a bash script that can achieve the following: 1) list files that contain a certain string in order of their creation date. Ideally the script should ask me to type in the string by hand. 2) use that list and remove all except the last one created... (2 Replies)
Discussion started by: kjartan
2 Replies

6. Shell Programming and Scripting

Bash Script Help...search then read from file: change text and pipe back...

Hello, I am trying to make a bash script that can pull data from a file and then change one part of said data. I want to search by username and pull the full line. That way there is a way to replace just one part of that line then return it back to the file. My Data is stored like: ... (1 Reply)
Discussion started by: serverfull
1 Replies

7. Shell Programming and Scripting

Difficult problem: Complex text file manipulation in bash script.

I don't know if this is a big issue or not, but I'm having difficulties. I apoligize for the upcoming essay :o. I'm writing a script, similar to a paint program that edits images, but in the form of ANSI block characters. The program so far is working. I managed to save the image into a file,... (14 Replies)
Discussion started by: tinman47
14 Replies

8. Shell Programming and Scripting

Bash shell script that inserts a text data file into an HTML table

hi , i need to create a bash shell script that insert a text data file into an html made table, this table output has to mailed.I am new to shell scripting and have a very minimum idea of shell scripting. please help. (9 Replies)
Discussion started by: intern123
9 Replies

9. Shell Programming and Scripting

Bash script to delete folder based on text file information

I have been working on a script to list all the name's of a subfolder in a text file then edit that text file and then delete the subfolder base on the edited text file so far I have been able to do every thing I just talked about but can't figure out how to delete the subfolers base on a text file... (8 Replies)
Discussion started by: bone11409
8 Replies

10. Shell Programming and Scripting

Script for removing text from a txt file

Hello, So I wanted to write a very simple script to remove some information from a text file and save it as something else. For example I have a text file (let's call it txt) with three rows of numbers: 0 0 1 9 8 7 5 0 6 7 9 0 0 7 9 8 1 1 6 4 0 6 0 0 9 8 4 6 0 9 2 8 1 And I want to... (2 Replies)
Discussion started by: hertingm
2 Replies
Login or Register to Ask a Question