Programming :: File Renaming Based On A Pattern Match
Jan 8, 2011
What I am attempting to do is rename some television shows into the format that my PVR will understand for the naming convention. I have a script that cleans them up about 95%, now I just cant figure out the last little detail..
For example: NCIS_01.mkv
I think it can be done in sed, but I just figure out how. I need it to be renamed to: NCIS_s01e01.mkv
How can I make sed (or something else) match the last "_" and any numbers after it until the period and then insert text between them reliably?
Depending on the show, it can be something like: This_show_name_243.avi so I need it to be more flexible than I can figure out how to do..
View 6 Replies
ADVERTISEMENT
Jun 26, 2011
I want to strip the process name from the hosts - i did it with the code below.
I have two questions - is there a more compact way to strip off the process names? usalso i want to get rid of the errors after extracting the hostname. It is complaing about $arry[1]. using my $arry[1] is not allowed. Assigning the slice to a value, as is 'my $sliced_arry = $arry[1]; print $sliced_arry , does not work either.
Code:
Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 16 here i get what i want - just the host name, but still get those nasty errors. assigning a value to $1 does not work, and localizing $1 with 'my' is not allowed.
Code:
View 4 Replies
View Related
Aug 30, 2009
I'm writing a bash script to search html files, and when I find any occurrence of an img src tag like this:
<img src="123-picture-normal.jpg" alt="some random user entered text" border="0">
I want to add a second line below it that looks like:
<img src="123-picture-thumbnail.jpg" alt="some random user entered text" border="0">
All I need to do is duplicate the line but replace "normal" with "thumbnail"
Each file can have multiple img src tags with different numbered jpgs.
I have a feeling this is a job for sed, but I'm struggling with it. Any ideas?
View 2 Replies
View Related
Feb 24, 2010
I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern exists.how do i get the line number of the pattern and delete that line and replace the line with my new text?
View 1 Replies
View Related
Sep 3, 2010
I am interested in the following problem: given a string (pattern) find a regexp which match this pattern.
I will need this for a developing of an idea 'pattern based filtration'.
View 3 Replies
View Related
Oct 24, 2010
I have some lines of text and I want to detect words that meet some criteria with sed.
E.g. The line "tetris cat dog test cactus stereotype"
I want to detect the word that contains two (2) ore more t letters. That mean the words tetris, test and stereotype.
The following regex doesn't do the job because it can;t distinguish words very well.
I thinks I have ti incorporate something like [^ ] in the regex but I wasn't successful...
View 3 Replies
View Related
Apr 14, 2010
I have to use sed with this problem, and sed is extremely complicated, they could probably teach a whole class on this entire function.
Here's an example to show what I need to do:
Code...
how would I say that every line before I reach the first match of "sweet" should be deleted so that the output will look like: Code...
View 9 Replies
View Related
Aug 10, 2010
seemed to have buggered up installing netbeans on my slackware 13.0 machine. I got the source (the zip file), which i copied into the extracted slackbuild, then did a
Code:
./netbeans.SlackBuild
It all seemed to work fine, at the end it told me my package could be found in /tmp. So i went there and did a
Code: root@slackLap:/tmp# slackpkg install netbeans-6.8-i586-1_SBo.tgz
Looking for netbeans-6.8-i586-1_SBo.tgz in package list. Please wait... DONE
No packages match the pattern for install. Try: /usr/sbin/slackpkg reinstall|upgrade
ps i'm running 32bit slackware 13.0
View 3 Replies
View Related
Mar 14, 2011
I have a file called test. It has the following contents.Code:there youI want the output to be.Code:replaced youI am trying to use the sed command to replace every occurance of "hey newline there" with "replaced". I tried the following naive apporach.Code:sed 's/heythere/replace/' testThis gives a result containing the same data as the test file.
View 3 Replies
View Related
Apr 29, 2010
I have to enhance the behaviour of a backup script written in perl. I don't need to change it, what I need to do is to create a bash script that does some checks like file name and file size, execute the backup script then check if the backup files match the original files.Here's how I try to do it:
- read the files from the original files folder
- store them in an array
- search in the array the files that have a specific file extension
- store the file names that match the search pattern (I know the backup script skips some files so I can hardcode the search pattern)
- run the backup script
- read the files from the backup folder
- store them in an array
- compare the original files name and size stored in an array with those from the backup folder
- send a report email
View 3 Replies
View Related
Jun 16, 2011
I have an interesting problem, sed '/pattern/{n;p;}' file, doesn't seem to be catching all of the matches in my file. As an example of this see below.test:
Turn
Turn
Turn
[code]....
View 5 Replies
View Related
Apr 12, 2010
I have two files, where the 1. file has special lines that need to be updated by lines from a 2. file:file1:
foo
foo
foo 0.00 0.00 0.00 pattern
[code]....
View 1 Replies
View Related
Jun 6, 2010
I have a file which contains milion of records. It contains 12 columns seperated by "||" (delimeter).
First two fields contain first name and last name of a person. Now my requirement is to delete all those records from this file for which:
First two fields does not contain any alphabet.
For e.g i have below mentioned records in file:
gaurav||gandhi||123||456||789
#a%bcd||123abc||89|90||91
12345||@@@||89||123||234
***||!!!!||98||76||90
Now, last two lines should be removed from this file since first two fields does not contain any alphabet for these two records.
View 12 Replies
View Related
Mar 4, 2010
Suppose i have a file(1.txt) separated by TAB delimiter in a line
1 B AB 2
2 C AB 2
if I need to search for the records having B?? using grep.If i need to perform multiple search like line having "C and AB" or "B and AB"??
View 5 Replies
View Related
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
Mar 17, 2009
I'm trying to find the correct sed syntax to match from a given pattern to the end of the file and then append that pattern to the end of the file.
I was trying:
But that prints each line right after its original occurrence. I want to match the block and then append it to the end of the file.
View 12 Replies
View Related
Jul 20, 2010
Is there a way to do a batch renames of files that will keep each individual filename, but change it in the way I want?
The specific issue is this. I have a harddrive with something like 1300 movies on it. They're all organized alphabetically, but there are like 200 movies that begin with 'The'. I want to rename all of these movies that begin with The so that the The at the beginning is dropped and added at the end (for example, turn "The Shawshank Redemption" into "Shawshank Redemption, The"). I'd like to do this with a simple command if its possible.
View 2 Replies
View Related
Sep 16, 2010
I have such a file(test.txt):
abc 123 456
abc 256 145
axd 125 225
[code]...
View 8 Replies
View Related
Oct 21, 2010
I have the following query:
Code:
$sql="SELECT table1.datetime, table1.user_id, table2.ip, FROM table1,table2 WHERE id='$id' AND (table1.id = table2.id AND table1.datetime = table2.datetime)";
In table2 the datetime fields are about 1 to 2 seconds off due to the source of the data, which I cannot change.
Is it possible via a query match table1.datetime & table2.datetime by HH:MM (ie. to the minute instead of to the second)?
View 1 Replies
View Related
Aug 4, 2011
I have hundreds of MTS and AVI files since 2000 and would like to rename them in the following manner based on the date created: DD-MMM-YYYY HH.MM.SS_X; where X begins at 1 and increments by 1 if there are dublicate date/time stamped videos.
Ex: 19-Nov-2002 08.12.30.avi, 19-Nov-2002 08:13:30_1 and 19-Nov-2002 08:13:30_2
Someone previously wrote the following script for me, and it works great for photos. It uses EXIV2 to get the image date created info. I have tried to understand the script, but am struggling. The video files I have can use the date modified since I have not modified them since I filmed them.
#!/usr/bin/env python
import os
import stat
import pyexiv2
import time
directory = '/home/david/Desktop/test'
[Code].....
View 1 Replies
View Related
Jun 5, 2010
i have the follwing code
touch umer.txt
fdisk -l | grep 'Disk /' umer.txt
read file
[code]...
View 7 Replies
View Related
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
Dec 25, 2010
i have a file like this
# comments
#comments
#comments
bla bla
[code]....
i want to grep lines which do not start with # or a blank space. like
bla bla
bla bla
how do i do this? i tried grep --invert-match '^#' which gives lines not starting with # but gives me blank lines too i tried grep --invert-match '^#|^ ' which will give lines not starting with # OR not starting with blank ( which means any line including ones starting with #
View 3 Replies
View Related
Jul 27, 2010
I am splitting a file based on the values read from an input file. The below one is the script.
1)How do I add the header which is present in the original file to the new split files created?(For eg. pharmacyf conatins header as table column names. The new files created (ODS.POS.$pharmacyid.$tablename.$CURRENT_DATE.dat) are without the header).
2) Also the script is creating 0 byte files for the pharmacyids which are not available in the intial file? Can this be avoided?
for pharmacyf in *
do
tablename=`echo $pharmacyf |cut -f4 -d'.' `
while read pharmacyid
do
grep -w $pharmacyid $pharmacyf >> $OUT/ODS.POS.$pharmacyid.$tablename.$CURRENT_DATE.dat
done< inputfile
done
View 2 Replies
View Related
Nov 22, 2010
I have several (vhdl) files containing a pattern with newline characters that I need to replace by another pattern that also contains newline characters.
I start with something like:
Code:
I want to replace it by something like:
Code:
(I need to paste some lines)
As I need to do this (very) often I want to use a shell script.
I tried:
1.
Code:
result:
Code:
2.
Code:
result:
File remains unchanged
3.
Code:
result:
Code:
4.
Code:
result:
Displays the unchanged testfile
How I can automate the pattern replacement?
Code:
View 9 Replies
View Related
Jul 19, 2011
Is there any API to get partition name based on file path in C on Linux OS?
View 1 Replies
View Related
Jun 21, 2011
I a csv-file (A.csv) with a total of 4.600.000 lines. Thats to many and only a few is necessary. I have a txt-file with 150 lines (X.txt) (all lines is dataset from a mainframe and looks like abc.def.123.456. How do I remove lines from A.csv where none of the dataset from x.txt is present?
View 13 Replies
View Related
Jun 10, 2010
I have multiple HTML files in a folder. there is a <h2> tag like this:
Code:
<h2>some text</h2>
in each file. I want to write a shell script/batch file to add this tag in <head> section of each file:
Code:
<!-- TITLE= "same text from h2 tag" -->
Note that <h2>some text</h2> in some files has 1 or more linebreaks and so I couldn't capture tag content using a simple grep or...
for example:
<h2>first part of text
second line of text</h2>
The line break shouldn't be shown in <!-- TITLE= "same text from h2 tag" -->. The script has to capture tag content & skip line breaks.
View 3 Replies
View Related
Apr 1, 2009
Was wondering if any perl guru's could help me with a quick log file adjustment. I have a text file that looks like so (tabs and newlines are revealed so you can see what separates the data):
There are maybe 100 lines of text in this file at any given time. I need to delete all duplicate lines only looking at the first bit of text prior to the first tab. It doesn't matter which one gets deleted as long as there are no two lines that begin with that same text at the beginning before the first tab. So in this example, either the fist line "1234" or the last line "1234" would need to be deleted. I already have code in my script that opens the files - I just need the code to read the text into an array and the part that would find matches based on the above criteria, and make the deletions.
If it would be easier, I can even do a system call and use SED (v4.1.5) and/or AWK (3.1.5) instead.
View 7 Replies
View Related
Apr 12, 2010
I'm writing a bash shell script that among various other things will traverse through a directory with hundreds of files and rename those who match a pattern found in a config file. It's expected that only about one in ten files will actually match, and those who don't, will simply just be ignored for this purpose.
This should for instance cause the file "dBase program file December 1987.prg" to be renamed "Clipper source code December 1987.prg", and conversely "C++ source August 1996.cpp" to be renamed "C source code August 1996.cpp" etc.A sample file such as "Random Data File.dat" should not be renamed here since it's not mentioned in the config file..What is the quickest, most elegant way to do this in bash?I am thinking of using bash's built-in regex matching combined with the /bin/rename utility, but don't quite know how to get started to catch this..I guess there are plenty ways of doing this in perl and elsewhere as well, but since this has to integrate into a pre-existing bash script, that's what I'm looking for.Anyone out there with a spare moment to offer a hint in the right direction?
View 14 Replies
View Related