Grep For Mp3 Mac



Mac OS X Command Line 101
by Richard Burton

Understanding The 'grep' Command In Mac OS X
Part XV of this series...
October 4th, 2002

I don't know why Dudley keeps trying to find himself, I found him years ago.
-
Peter Cook

This series is designed to help you learn more about the Mac OS X command line. If you have any questions about what you read here, check out the earlier columns, write back in the comments below, or join us in the Hardcore X! forum.

In the previous column, we learned about regular expressions, and how to use them to search for text in vi. Having such a text-searching tool for the command line would be a valuable addition to Unix; naturally, such a tool exists. It is called grep, and it is the subject of today's column.

grep allows you to search through your entire system, for either the name of a file, or for content within those files. This is similar to the way Sherlock used to work before Sherlock 3, and the way 'Find' works today in Jaguar's GUI. When you need to find a string of text on your system from the command line, grep is the way to do it. Now, on to how to use it.

The grep command will take a regular expression, as well as a list of files. It will then search through the files and, for each line that is matched by the regular expression, print the line. (Supposedly, the name grep comes from ed command g/RE/p, or 'global/regular expression/print', which does the same thing within the editor. I can neither confirm nor deny this.) If there are no files indicated, grep will read from standard input. Therefore, you can do things like:

to give a more flexible search. Notice that the regular expression, .es.*, was enclosed in double quotes. Otherwise, we get this:

[Note: I think that this is because the asterisk and/or period will confuse the tcsh command line, which tries to use them as metacharacers, so you need the quotes. On the other hand, if you want to anchor the regular expression to the end of a line with a dollar sign, it interprets this as a variable $' and chokes. tcsh is quirky with regular expressions, and I haven't quite figured out everything with it. I know from experience that the Korn shell, ksh, does not suffer from this. On the other hand, ksh is not the default shell, so there y'are.]

You also need quotes if you have spaces in the regular expression. The difference between grep the file and grep 'the ' file is that the former will match any occurrence of t-h-e, whereas the latter will match only for t-h-e-space. This means that the former will match 'I was there' but the latter will not. Remember that the command line ignores extra spaces, collapsing many into one, unless the spaces are quoted.

As you might expect, grep takes the standard regular expression characters of ., *, ^, $, , and [ ]. Thus, to count the number of blank lines in a file, do:

Thus, we can see that grep ^$ testfile will print all three blank lines. We can use wc and the pipe, |, to build our own tool to count blank lines. Neat, huh?

In some Unixes (Unices?), there were two versions of grep, grep and egrep, whose primary difference was that each had slightly different additions to the basic regular expression syntax. In Darwin, and therefore in OS X, the syntaxes (syntaces?) are combined, and using either command will get you the same as using the other. Thus, you can bounce back and forth between them like so many yo-yos (yo-yi?)[*]

One set of regular expression characters available in grep is the { } pair. This allows you to search for a range of occurrences. Suppose you want to look for 'to', followed by three to nine characters, follow by an 'a'. This can be done by:

Again, the quotes are needed here. If you want to match exactly 3, the regular expression is to.{3}a. Normally, the { } pair is only available in grep, but in Darwin and OS X, it is also available in egrep.

grep's regular expression syntax is expanded in OS X to include features not seen in the standard definition of grep. In other words, OS X'sgrep will let you do searches that greps on other Unices won't. For example, you can use the < > pair to denote the beginnings and endings of words, just like in vi.

We have seen that the asterisk (*) is used to denote 'any number of the thing preceding me.' In OS X'sgrep, the plus sign, +, can be used to denote 'at least on of the thing preceding me.' So, while the regular expression th*e will match te, the, thhe, ..., the regular expression th+e will match the, thhe, thhhe, .... So can see that h+ is the same as hh*. The plus sign is often used in other utilities' regular expressions, but is not part of grep on most other systems. Make a note of it, there will be a quiz later.

Another bonus freebie that is thrown our way is the question mark, ?, unless you are British and over 35, in which case it is 'a mark of interrogation.' grep uses this in regular expressions to denote 'zero or one occurrence of the thing before me', or 'an optional [whatever is before me].' Therefore, the expression lie?d will match either lied or lid.

Finally, the vertical bar, |, can be used for either/or matching, just like in, you guessed it, vi.

grep can take several options; you can see them all via man grep, of course, but I've found that the most useful ones are (remember that this works in the grep option format):

-c: 'count the lines'. Instead of printing all the matched lines, -c merely prints a count of matched lines for each file. Thus that '| wc -l' trick isn't needed for one file. (If you pass in a list of files, though, ...)

-e PATTERN: 'expression starts here.' Using -e will tell grep 'What follows is the pattern with which to search.' This is very useful when your pattern starts with a '-'. Otherwise, the command line might think that your expression is an option and get confused.

-f FILE: 'file holds the expression'. -f allows you to store a pattern in a file and tell grep 'Yo, use this.' I've mostly used this when writing scripts that will use the same pattern repeatedly. That way, if I have to change it later, I only have to change it in one place.

-i: 'ignore case'. -i forces grep to ignore the distinction between uppercase and lowercase. Imagine you need to find matches in a file which may have come from Windows (include shudder here). Now imagine a long string of paired letters like [Tt][Hh][Ee] [Cc][Aa][Tt] and on and on. Just use -i instead and save yourself time and pain.

-l: 'list files'. Instead of printing the matched lines,when you use the -l option,grep will just print a list of the files which contain the expression. This is mostly used when you are doing something like grep 'expression' * in a directory with a lot of files or when you just want to know which files need (processing, editing, etc).

-n: 'number'. -n means that before each line of output, grep will print its line number within the file.

-v: 'invert'. -v instructs grep to print only those lines that don't match the expression.

As you can see, grep is a very powerful tool. It can be used to quickly search files and to filter output on the command line. It does have a couple limitations, though. First, it is no speed demon. Building those regular expressions and parsing a lot of text in a flexible way takes resources, and that takes time. (Admittedly, these days, that isn't much of an issue, but still, there it is.) Second, consider the following: you are working away, happy as a clam, and the boss says 'Cyprian', if your name is Cyprian, 'I just got a call from marketing, we need to change the search in all those voodoo scripts you wrote, and we need it in ten minutes.'

Now, you know and I know that you can look for the expression the.?.*ca[r]?t and search for it using after after . But my lord, and your duke for that matter, who the heck would want to? Do you realize that you would look for the.?.*ca[r]?t (or something along those lines) and heaven forbid you should make the slightest mistake. If you're like me, and I know I am, you'd think 'Now dash it, there must be an easier way. Surely, in all the history of Unix, someone has had to face just such an emergency and written a grep-like tool to deal with this. Like that Cyprian chap, maybe.' Well, Cyprian has come through. It's called fgrep (for 'fast grep'), and it works a lot like grep except it doesn't take a regular expression.

Where you would normally place a regular expression, just put in a literal string. Originally it was used to be a fast alternative to grep by trading the power and flexibility of regular expressions for speed. As quick as computers are these days, that isn't an issue, but if you want to find something that contains a literal period or a literal asterisk, it's the bee's knees.

[*] This joke was borrowed at great embarrassment from Shelley Berman. All young whippersnappers are advised to ask their parents or grandparents.

You are encouraged to send Richard your comments, or to post them below.

Most Recent Mac OS X Command Line 101 Columns

Command Line History & Editing Your Commands
November 22nd

Pico: An Easy To Use Command Line Editor
November 1st

Understanding The 'grep' Command In Mac OS X
October 4th

Command Line History & Editing Your Commands
September 6th

Mac OS X Command Line 101 Archives

Back to The Mac Observer For More Mac News!

Richard Burton is a longtime Unix programmer and a handsome brute. He spends his spare time yelling at the television during Colts and Pacers games, writing politically incorrect short stories, and trying to shoot the neighbor's cat (not really) nesting in his garage. He can be seen running roughshod over the TMO forums under the alias tbone1.

Though MP4 (MPEG4 Part 14) is the most popular video format that could be used almost anywhere like online video sites and camcorders, sometimes you may want to convert MP4 videos to MPEG videos so you could handle these MP4 videos in computer, DVD player, some video editing programs, etc. To convert MP4 to MPEG, all you need is an expert video converter that could process the MP4 to MPEG-1 or MP4 to MPEG-2 video converting. We showed you how to convert MPEG to MP4 before. Here we show you how to convert MP4 to MPEG on Mac and PC.

Part 1: Convert MP4 to MPEG on Mac and PC with Leawo Video Converter

Grep For Mp3 Mac Free

Converting MP4 to MPEG is easy with the help of Leawo Video Converter. To do the same task on Mac, you can use its Mac counterpart Leawo Video Converter for Mac. The steps on Mac and PC are nearly the same. So here we will take one version of the program as an example, say Leawo Video Converter, to convert MP4 to MPEG on PC. Mac users can follow suit to convert MP4 to MPEG on Mac with Leawo Video Converter for Mac.

Leawo Video Converter would be the most cutting-edge MP4 to MPEG converter recommended due to its multiple functions, high performance and ease of use. As a professional video and audio converter program, it can handle almost all kinds of video and audio conversions between more than 180 formats, including MP4 to MPEG, WMV to MP4, MKV to AVI, WMV to MOV, etc. It also allows you to convert video to various portable devices including Apple devices, Android devices and Windows phones, etc. As an MP4 to MPEG converter, it offers a quite effective solution to finish the conversion in only a few clicks with original quality reserved at very high speed. Moreover, it comes with a built-in editor that allows you to personalize your video files so that you could customize the video as you like, including trimming the video length, adding watermark, cropping the video, converting 2D to 3D video with different effects, removing the background noise and adding video effects.

Ls command is used to list information about directory contents (the current directory by default), which included files and folders. There are many file types and Type the ls -lh command to list the files or directories in the same table format above, but with another column representing the size of each file/directory: Note that sizes are listed in bytes (B), megabytes (MB), gigabytes (GB. Download Grep for Mac to perform rapid and accurate search on extensive plain-text data sets with ease. Grep has had 0 updates within the past 6 months.

Download and install the right version of Leawo Video Converter based on the operating system on your computer. Follow the guide to convert MP4 to MPEG with Leawo Video Converter.

Step 1. Import Source MP4 Video File
Launch Leawo Video Converter, go to the “Convert” tab, and click “Add Video” button on the sub-menu to load your source MP4 video file. Alternatively, you can directly drag and drop MP4 video file into the program interface. After MP4 video file is imported, you could play back MP4 video file, select subtitles and audio tracks from source MP4 video file, add external subtitles to loaded MP4 video file, edit loaded MP4 video file, etc.

Machine

Step 2. Set MPEG as Output Format
Click the drop-down box named “MP4 Video” by default next to the “Add Photo” button. On the drop-down list, select “Change” option.

Then on the popup Profile window, select “MPEG” from “Format” column as output format. To be more specific, if you want to convert MP4 to MPEG-1, you need to set MPEG-1 as output format, and you need to set MPEG-2 as output format if you want to convert MP4 to MPEG-2. Please note that once you change the output format, the name of the drop-down box will change as well.

Note: If you need, you could click the “Edit” button on the drop-down profile setting box to adjust video and audio parameters like video codec, aspect ratio, frame rate, resolution, audio codec, bit rate, channel, sample rate, etc. After editing job is done, click “OK” to return to the main interface.

Step 3. Convert MP4 to MPEG
Click the big green “Convert” button on the sub-menu bar next to the format setting drop-down box. Then, on the popup sidebar, set output directory. After setting output directory, click the “Convert” button right below. Leawo Video Converter would start to convert MP4 to MPEG immediately. After the conversion process is finished, you can find converted file in MPEG format in the output folder you just set.

Part 2: Convert MP4 to MPEG on Mac and PC with Anymp4 Video Converter

The second MP4 to MPEG converter is Anymp4 Video Converter, which is able to convert almost all 4K / HD / SD video formats, such as 4K H.265/HEVC Video (*.mp4), 4K H.264/MPEG-4 AVC Video (*.mp4), WebM-VP9 4K WebM Video (*.webm), AVI, FLV, MP4, WMV, MOV, 3GP and so on. Follow the guide below to convert MP4 to MPEG with Anymp4 Video Converter.

Step 1. Add Source MP4 Video File
On the main interface of Anymp4 Video Converter, click “Add File” to choose and add source MP4 video file.

Step 2. Choose MPEG as Output Format
Before you choose any output format, you can click “Edit” button on the main interface to rotate/crop/enhance video, apply video effects or watermark as you like. After that, you need to click “Profile” column and choose MPEG as the output format, and then click “Browse” to choose a folder to contain the output file.

Step 3. Start to Convert MP4 to MPEG
Click “Convert” button at the bottom right to convert MP4 to MPEG. After a while, you can find files in MPEG format in the output folder you just set.

Part 3: Convert MP4 to MPEG on Mac and PC with Any Video Converter

Any Video Converter is a simple, all-round video converter. It supports high-speed and quality-lossless conversion, allowing conversion in several video formats, and it can convert videos including DivX, XviD, MOV, RM, RMVB, MPEG, VOB, DVD, WMV, AVI to MPEG-4 format into your iPod, PSP, MP4, mobile phone or other video playback tools.

Step 1. Download and Install Any Video Converter
It takes only a few minutes to download and install Any Video Converter. If you are using Mac version, you can download and install Mac counterpart of Any Video Converter.

Step 2. Add MP4 Videos for Conversion
Launch the program you just installed. As you can see from the operator interface, there are many options to choose from, such as 'Convert Video', 'DVD Burning', 'Recording Video', 'Playing Video'. You can drag the source MP4 file directly into the converter, or click the green 'Add Video' button to browse and select targeted MP4 video file on your PC.

Step 3. Choose MPEG as Output Format
After importing the MP4 video file, you need to click the drop-down box named 'select output profile', then select 'Video Files' and click 'MPEG'. The format of the output video is set.

Step 4. Convert and Enjoy Converted Video
After all the parameters are set, click 'Convert Now!' to convert MP4 to MPEG, and wait a few minutes, you can get MPEG format video.

Part 4: Convert MP4 to MPEG on Mac and PC with VideoProc

VideoProc is a piece of fast video processing software that is able to achieve video and audio conversion between formats, including MP4 to MPEG.

Step 1. Add Source MP4 Video File
Click '+Video' button to import one MP4 video or multiple MP4 videos (for batch transcoding) into the program.

Step 2. Choose MPEG as Output Format
Click 'Video' tab on the bottom of the interface. Many popular video formats are presented. Select MPEG as output format for converting MP4 to MPEG. And then click 'Browse' button to set a new destination folder.

Step 3. Start to Convert MP4 to MPEG
Click 'RUN' button to start converting MP4 to MPEG.

Part 5: Convert MP4 to MPEG on Mac and PC with FileZigZag

The fifth one is an online solution with the help of FileZigZag, which supports thousands of types of unit conversions, making it easy for users to reach a one-stop shop without having to jump from one location to another. Here we convert MP4 to MPEG with FileZigZag.

Step 1. Import Source MP4 Video File into FileZigZag
The interface of the web page is very simple. The first bar is for you to import file. Here, we choose to import the pre-prepared MP4 video file.

Step 2. Choose MPEG as Output Video Format
Click the drop-down box under “Convert to”, and you need to select MPEG as the output video format in order to convert MP4 to MPEG.

Grep For Mp3 Mac Download

Step 3. Input Your Email Address and Start to Convert
In the third bar, you need to input your email address, and then click “Convert” in the fourth bar. After a while, the converted result will be sent to your email box. That’s it, and you will get converted result in MPEG video format.