General :: Regular Expressions In Batch Script?
May 5, 2010
I am pretty new at this topic but I would like to learn it from example. The first thing I am working on is to modify the command date to be shown as DD/MM/YY only using regular expression but I dont know how to combine what there is in the regexp tutorials online and the syntax for batch scripting. Any help?
Here is what I what.
run a file test: ~# ./test
Where file test is:
#!/bin/bash
#
DATE=$( date )
[Code]..
Also if you can point me to good regexp tutorials (directed towards batch scripting), that will be great.
View 8 Replies
ADVERTISEMENT
Apr 16, 2010
I'm writing a program that works with text files, and I'm trying to create some filters with grep. I have various questions here, so I'll number them for clarity.
1) First of all, I'd like to know what wc -w is actually returning. The word count is less than what gedit is counting in Document Statistics, so obviously gedit is counting something (like newlines) that wc -w is not
2) Secondly, I was wondering if there was a way to grep x number of words. I'm looking for something like the -m option, but returning a certain number of words instead of lines. For example, to find the first 2000 words, do something like grep -someoption 2000 ".*" or using {1,2000}.
3) Finally, I'm trying to filter out headers and footers of a text file but having no luck. The text files are Project Gutenberg files, so they have standardized headers and footers. Here's an example: [URL]...
The header starts with "The Project Gutenberg EBook of" and ends with the line containing "START OF THIS PROJECT GUTENBERG EBOOK" The footers begin with: "End of the Project Gutenberg EBook of" My problem is, grep can find:
[Code]...
View 15 Replies
View Related
Aug 3, 2011
I can't get this simple regular expression to work for matching emails: 'w*(?:.w*)*@w*(?:.w*)*w{2,5}'
It should be working as I have tested it with regex pal and it works just fine. I think there's a problem with optional character class but I'm not sure.
View 1 Replies
View Related
Aug 26, 2010
As the subject says, can anyone explain to me what is the difference between Regular Expressions and Globbing?
View 9 Replies
View Related
Feb 23, 2010
How to make tools like sed operate on the whole file, instead of line-by-line?
View 14 Replies
View Related
Nov 20, 2010
How can we do a simple match by regular expressions on two filenames. I plan to use it in the command 'find -regex'
Code:
hosts.txt
ipaddress.txt
View 4 Replies
View Related
May 6, 2010
Lets say I have 20 files named FOOXX, where XX is the number of the file, eg 01, 02 etc. At the moment, if I want to delete all files lower than the number 10, this is easy and I just use a wildcard, eg rm FOO0* However, if I want to delete specific files ina range, eg 13-15, this becomes more difficult. rm FPP[13-15] does not work, and asks me if I wish to delete all files. Likewse rm FOO1[3-5] wishes to delete all files that begin with FOO1 So, what is the best way to delete ranges of files like this? I have tried with both bash and zsh, and I don't think they differ so much for such a basic task?
View 2 Replies
View Related
Aug 15, 2010
I want to use regular expressions and sed to remove html tags from a text file.
View 2 Replies
View Related
Mar 29, 2010
how a way that I can edit the metadata tags on some MP3s using regex?
I've got almost 100 MP3, all named "01 - <song title>," "02 - <song title>," etc., and I, understandably, don't want to edit them all by hand.
Running "s/d{2} - //g" would be so much easier.
View 4 Replies
View Related
Mar 26, 2011
I've began to develop with C++ (Eclipse+Qt) and the first problem I see is that there is not good functions for manipulating strings. if there is a library for manipulating strings with regular expressions?
View 1 Replies
View Related
May 31, 2011
i am trying to create an exclude regular expression for my build.xml. The problem is, that i am trying to find some info on which REs are acceptable/valid for ant... Is ant using standard regular expressions? POSIX ones? Since it is a java-based tool, the "Java REs" are probably valid. I am a little bit confused. If somebody can help me out with the different RE standards, i would be most obliged.
View 1 Replies
View Related
Mar 17, 2010
Gidday, I'm puzzled as to why this works:
Code:
find /Data/ -type f -iname "*7pm*"
But this doesn't:
Code:
find /Data/ -type f -regex *7[Pp][Mm]*
I've tried MANY variations, but I'm getting no error messages, just no returns, and yet the first find, will find the sorts of files I'm looking for. I realise a win is a win, but I'm of the understanding that the -regex switch allows for some really complex use of regular expressions - but I can't even get a very simple one to work,
View 4 Replies
View Related
Jan 12, 2010
The * would not have to be because it means everything [az] [0-9 ][$%&!"/()=?'=) but not how to solve[URL]..
ls [0-9a-zA-Z]*[@]*[gmail | yahoo | hotmail]*[.]*[com]
ls [0-9a-zA-Z][.-_][0-9a-zA-Z]*[@]*[gmail | yahoo | hotmail]*[.]*[com]
View 2 Replies
View Related
Jun 8, 2010
How do I make Vim use extended regular expressions?
I really wish I wouldn't have to use all these ugly backslashes to do backreferences.
View 3 Replies
View Related
Sep 9, 2010
Is it possible to point to a two-digit interval with regular expressions?
Background:
I'm using mplayer to watch tv shows, that often have episode numbers in their names. I know how to easily add several files to the playlist by using brackets, by typing something like
$ mplayer tv/South.Park.S1.E0[1-5]*avi
Is there a way to point to files 06-13 in a single expression?
View 2 Replies
View Related
Aug 19, 2010
Here's my need:
If Calendar Day= Then FCPeriod= And FCYear=
Jan 11 to Feb 1002Current Year of Feb 10
Feb 11 to Mar 1003Current Year of Mar 10
Mar 11 to Apr 1004Current Year of Apr 10
Apr 11 to May 1005Current Year of May 10
May 11 to June 1006Current Year of June 10
June 11 to July 1007Current Year of July 10
July 11 to Aug 1008Current Year of Aug 10
Aug 11 to Sept 1009Current Year of Sept 10
Sept 11 to Oct 1010Current Year of Oct 10
Oct 11 to Nov 1011Current Year of Nov 10
Nov 11 to Dec 1012Current Year of Dec 10
Dec 11 to Jan 1001* Current Year of Jan 10
* Note for Dec 11 - Dec 31,
The Next Year to be used
IE: Current date is Dec 28th, 2010. Year = 2011
IE: Current date is Jan 8th, 2011, Year = 2011.
Looks like I'll need a case statement with some regular expressions...
View 9 Replies
View Related
Feb 2, 2011
What I am doing is reading the text from a text document and storing all of the text inside of a ArrayList. I then set one of the values of the Arraylist as a string. I want to use regular expressions find out what the first two characters of the String are. if first two characters = "//" then function(); I only care about the first two characters though. If you need any more information, just ask.
View 4 Replies
View Related
Mar 28, 2010
How can I use grep expressions so that i can find strings like the ones bellow:
New York, NY
Virginia, VA
Oregon, OR
As you can see each city starts with capital letter then it follows up with a comma, and then with the Abbreviation of the city. I used :
Code: grep -w '[A-Z].*[a-z][,][' '][A-Z][A-Z]' filename But i get no results.
View 2 Replies
View Related
Jul 29, 2010
I am trying to learn more about global expressions and how it is needed in changing stuff in vi and in shell scipting in general.My question is basic:
How can I add a " # " pound sign at the beginning of every line in a file. So if I want to remark out every line in a file, what would be the global expression for that? Is there a global expression cheat sheet?
View 4 Replies
View Related
Mar 13, 2010
I need to edit myfile in a script.I tried items below but it did not change anything.
myfile:
141 aaaa bb Jun 4'09su Jun15'09mo yyyy
206 vvv nn Jun 4'09su Jun16'09tu tt
208 bb yyyy Jun 4'09su Jun15'09mo vvvvvvvv
[Code].....
View 6 Replies
View Related
Sep 26, 2010
I have several program windows open on my main display (showing on my physical screen).I've created a second display for VNC connections (using vncserver :14).Is there a way I can move all open windows from the default display to the VNC display?
View 1 Replies
View Related
Oct 14, 2010
I am logging the output of: top -b -n1 -c so I can keep track of which processes are using how much memory and CPU each minute. When top shows the full command line (-c), the command line text gets truncated at the edge of the screen. This is perfect when running and displaying in a terminal. However, I am sending STDOUT to a file for parsing later and want the full command name logged. Is there a way I can tell top to use a specific screen width? (I know it maxes at 512, that would be fine)
Is there a better way to achieve a similar goal: get periodic stats about which processes are running and how many resources they are consuming?
View 2 Replies
View Related
Dec 11, 2010
I run a script which generated about 10k files in a directory. I just discovered that there is a bug in the script which causes some filenames to have a carriage return (presumably a '' character).
I want to run a sed command to remove the carriage return from the filenames.
Anyone knows which params to pass to sed to clean up the filenames in the manner described?
I am running on Linux (Ubuntu)
The character causing the filename to 'break up' accross multiple lines appear to be a CR (carriage return) instead of ' '. The filename is being diaplayed in thetitle of a text editor with %0D in the positions of where the file name breaks up. So I need to remove the CR chars from my filenames.
View 1 Replies
View Related
Feb 17, 2011
I'm looking to, all in the course of one batch file:
ssh into a remote computer execute commands (per the batch file) on the remote host.
What options do I need to add to the ssh invocation so that the batch file executes the lines following the ssh invocation over the connection?
e.g., with sftp it's simply adding a -b /dev/stdin and then << EOF at the end; how do I do this with SSH?
View 1 Replies
View Related
Sep 30, 2010
I just learnt to convert a video file into mp4 format so I can watch it on my PS3. However, I have dozens of video files from my video cam, and want to convert them all. They are all in the same folder. Please can someone explain how I might be able to adapt the code below so I can convert all my files in a batch. Perhaps keeping their same name or giving them some other name, I don't mind.
View 6 Replies
View Related
Feb 2, 2011
I've created a .bat file with this line: start C:USERSPuttyputty.exe -ssh user@server.com -pw password
That opens a putty session and logged in it with the user and password i've already specified. But now, I want to enter a simple command like "ls -l" for example.. How can I do that?
I've also tried plink...The line in that case is this one:
start C:USERSPuttyplink.exe -v -ssh user@server.com -pw password -m UNIX_commands.txt
and in that file "UNIX_commands.txt" I've added the following lines:
cd /projects/test
ls -l
all works fine (the commands are executed) but i can't see the putty session... all i can see is the verbose in my DOS windows of the last line "ls -l"...
The putty session vanishes away. How can I have the session opened and list the mentioned directory.
View 1 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
Apr 22, 2011
I have many video files that I'm trying to convert from *** to .mp4..Currently I'm using Handbrake which does a good job but getting it started is very tedious. In Handbrake I need to confirm and add to queue all of the files. When there are over 200 files at a time it takes way too long. If there is a way to not confirm all of the files please let me know.What program can I use to just add a folder and have it automatically add all of the files to my queue?
View 9 Replies
View Related
Jun 28, 2010
I have a web app that has a bunch of symbolic links in subdirectories throughout it.I need to move the app to another directory structure, and I need to update all the symlinks to point to the new path.The problem is that there's a lot of these scattered throughout various directories.How can I recursively search from the root and recreate all symlinks pointing to /dev/ with /qa/?
View 3 Replies
View Related
Aug 8, 2010
I need a way to batch convert 720p video files from avc1 to xvid in Ubuntu 10.04. I'm not terribly concerned about file size, but I do wish to retain the picture quality as much as possible. I believe the audio is encoded as aac, which is fine for my purposes.
What would be the best and easiest way to do this? I've tried using Handbrake. During my first attempt, I had it using ffmpeg to convert to MPEG-4, but that just gave me a super-low quality video at twice the file size. Trying h.264 now, so we'll see how that works out. But just in case it doesn't pan out so well, what other ways do you recommend?
I was thinking I'd write a bash script to reencode the files one by one, but the problem is that I have very little knowledge about codecs and containers and whatnot - so I wouldn't know what parameters I would pass ffmpeg/mencoder.
View 1 Replies
View Related