The Apple Pips

Inside All Apple Products

Tag: Mac (Page 1 of 244)

Getting Started with Terminal: What is sed and how does it work?

If you’re just getting started with Terminal, it can take a while to become familiar with the basic ins and outs of the command line interface. Once you have settled into a groove, you can start exploring some of the extremely powerful utilities available through the interface. One of the most useful is sed. It’s a slightly obscure program from the old days of Unix command line utilities. It uses powerful pattern matching to change text within files without opening them. What is sed, and how can we take advantage of its power?

What is sed?

sed is a command line stream editor. Its name comes from a portmanteau of those two words. While it does modify text, the application is not a text editor precisely. sed received text input as a “stream.” Then, it edits the stream according to your instructions. It can use complex pattern matching to make substitutions, or basic find and replace.

While this makes it useful for running find and replace functions on a batch of files, its not as easy to use as something from Excel or Word. However, sed is especially powerful when editing a number of plaintext files simultaneously. Though you’ll find that the syntax takes a little getting used to, once you’ve got that down, you’ll see how incredibly powerful this compact editor can be.

Using sed for substitution

To use sed, you’ll need to pop open a Terminal window. Because sed takes input, typing sed alone won’t do anything. Instead, you need give the application a command, as well as some parameters

The most common command is substitute, or s. A basic sed substitution functions like what’s below.

$ sed 's/cat/dog/'

That command will order sed to scan incoming text and replace every instance of the string “cat” with “dog.” To demonstrate, we’ll use the echo command to give sed something to work with.

what is sed guide

There are three main parts to the sed command. First, there’s sed, which starts the program. Then there’s the s, which starts the substitution command. The forward slash ( / ) is a separator, called a “delimiter.” The string after that will be the string sed looks for. The string after the second slash will be the replacement characters that sed writes to the stream. The final slash closes the command. All together, it’s 's/find/replace/'.

what is sed command components

Note the single quotes in that example. The single quotes allow you to use meta characters in your command. While quotes aren’t essential for most of our examples, you should develop the habit of using single quotes for all commands.

Matching partial strings

By default, sed does pay attention to word boundaries. If you ask it to replace the string “cat,” it will replace every appearance of those three letters. For example, “catapult” with become “dogapult” and “catamaran” will become “dogamaran.” To match word boundaries, you’ll want to use regular expressions in your pattern.

what is sed guide

 

Global replacement

Like many GNU utilities, sed is line based. This means that sed will only operate on the first match per line of the document. When the command encounters a newline, it resets and begins replacing again. Typically, this isn’t ideal, but it’s simple enough to disable. To make sed operate on every appearance of the pattern, add the g flag at the end of the command, like so:

$ sed 's/cat/dog/g'

This has the desired effect of replacing every appearance of that pattern with your replacement string.

$ echo cat catapult catamaran | sed 's/cat/dog/g'
dog dogapult dogamaran

Setting input and output files

By default, sed will operate on standard input. As a result, this means that it works on Terminal’s own text output, and process results to standard output. By and large, it’s more useful to process specific files. We can run sed on a file by specifying the filename at the end of the command:

$ sed 's/cat/dog/g' oldfile.txt > newfile.txt

what is sed guide

This will run sed on “oldfile.txt” and save the command’s output “newfile.txt.” The caret ( > )routes the output of “oldfile.txt” to “newfile.txt.” If “newfile.txt” does not exist, sed will create it as specified. If you don’t specify an output file, sed will print its results into Terminals standard output.

Writing files in place

We don’t always want route our replacements to a new file. If you want to overwrite the contents of a file, you’ll need to use the -i flag. This flag makes the edits “in place.” Keep in mind this is destructive, and will permanently eliminate the old version of the file.

$ sed -i '' 's/cat/dog' oldfile.txt

what is sed guide

If you want a little bit of a safety net, create a backup when the command executes. To create a backup of the file, put any file extension after the -i. It doesn’t need to be a functional extension: “.bu” or “.bak” are often chosen. While these extensions make the file inoperable, it still contains all the right bits. Just remove “.bu” or “.bak” from the filename and you’ll be able to open it.

$ sed -i.bak 's/cat/dog' oldfile.txt

This creates “oldfile.txt.bak”, which contains the unedited text data from the original version of “oldfile.txt.” The specified file, “oldfile.txt,” will now contain the updated contents based on sed’s replacements.

Matching regular expressions

The real power of sed comes from matching regular expressions. This allows you to set patterns for matching, rather than literal strings. For example, we could use something like the string below to repeat any set of one or more numbers:

$ echo "123 abc" | sed 's/[0-9][0-9]*/& &/'
123 123 abc

what is sed guide

Further Learning

Because sed an extremely powerful utility, with a depth of power similar to a scripting language, this guide is insufficient to cover the whole thing. To learn more about sed’s full capabilities, check out Bruce Barnett’s comprehensive guide to sed. But be ready to do some serious reading!

Getting Started with Terminal: Must-Know macOS Terminal Commands

Getting Started with Terminal: Using Grep to Search Files

Getting Started with Terminal: An Introduction

The post Getting Started with Terminal: What is sed and how does it work? appeared first on Apple Gazette.

Scrivener 3 Writing Suite for macOS Now Available – Features Overhauled Interface and New Compile System

Literature and Latte has announced the release of Scrivener 3, a comprehensive update to their popular long-form writing suite. The first version debuted on the Mac more than 10 years ago. The new version brings a long list of new and improved features, including a revamped interface.

Scrivener 3 Writing Suite for macOS Now Available - Features Overhauled Interface and New Compile System

Scrivener 3 is a major update to Scrivener that not only brings some very cool new features but also improves and simplifies what was already there. To name just a few improvements:

  • The interface has been overhauled and modernised.
  • Compile has been redesigned and is now not only much easier to use but also more flexible.
  • The text system now has a full styles system (which is even more powerful when used with the new Compile).
  • View index cards on coloured threads based on label colour (great for tracking different storylines or anything else).
  • Epub 3 and improved Kindle export have been added.
  • Keep track of how much you write each day using Writing Statistics.
  • Improved Custom Metadata allows you to add checkboxes, dates and list boxes to the Inspector and outliner.
  • Enhanced outlining.
  • Corkboard and outliner filtering.
  • Refer to up to four documents in the main window using the new “Copyholders” features.
  • Quickly find any document in your project using the new Quick Search tool.
  • See draft and session progress bars in the toolbar.
  • The powerful new Bookmarks feature replaces Project Notes, References and Favorites, and allows you to view oft-needed documents right in the Inspector.
  • Use “Dialogue Focus” to pick out all the dialogue in your text.
  • Export rich text to MultiMarkdown or Pandoc.
  • Broadened support for technical formats via Markdown output and custom post-processing.
  • macOS:
    • Extensive Touch Bar support added.
    • Modernised and rewritten codebase for 64-bit. Scrivener is faster, more stable and ready for the future.

Scrivener 3 Writing Suite for macOS Now Available - Features Overhauled Interface and New Compile System

Scrivener 3 for Mac is available for $45 from the Literature and Latte website. Owners of previous versions of Scrivener that were purchased through the Literature and Latte online store can get the new version for a discounted price. Scrivener 2 owners that purchased the app on or after August 20. 2017, can update to the new version for free. Scrivener 1 or 2 users who purchased the app before that can update to the new version for just $25.

iMac Pro Could Include A10 Fusion Chip for Always-On ‘Hey Siri’ Functionality, More

Developers digging into Apple’s “BridgeOS 2.0” code and macOS believe the upcoming iMac Pro could feature an A10 Fusion chip with 512 MB of RAM. The chip could enable always-on “Hey Siri” functionality, even when the computer is turned off.

iMac Pro Could Include A10 Fusion Chip for Always-On 'Hey Siri' Functionality, More

Developers Jonathan Levin, Steven Troughton-Smith, and Guilherme Rambo mused over the possibilities over the weekend.

Troughton-Smith says the A10 will manage the booting process and security for the computer, and that the chip might support always-on “Hey Siri.”

Rambo agreed with Troughton-Smith, and shared both the setup process for “Hey Siri” and a boot chime for BridgeOS.

In addition, a blog post at Pike’s Universum has dug into the Mac firmware files and says their is data related to mobile connectivity in the upcoming iMac Pro that could be used for theft protection similar to the Find My iPhone service.

Even the cheapest iMac Pro costs $4999 and is thus far more expensive than any other iMac model that is now available, let alone the top of the line one with a price tag north of $15K, and it is so easy to walk away with a 27-inch computer, and that may be why Apple is going to introduce a new kind of “Find my iMac Pro” type of theft protection. One that phones home to report the exact GPS location. And there’s no way of switching it off…

The iMac Pro debuted at Apple’s Worldwide Developers Conference in June, and is scheduled for launch in December. The high-end Mac will start at $4,999.

(Via MacRumors)

MacTrast Deals: Windscribe VPN Sale: 1 Year, 3 Year, 5 Year, and Lifetime Subscription Discounts

Windscribe VPN offers protection for your internet connections on your Mac and iOS devices. Just turn it on, and your connection is protected by a tunnel of encryption.

MacTrast Deals: Windscribe VPN Sale: 1 Year, 3 Year, 5 Year, and Lifetime Subscriptions

DESCRIPTION

Windscribe is much more than a VPN. It’s a desktop application and browser extension that work in conjunction to protect your online privacy, unblock websites, and remove ads and trackers from your everyday browsing. With Windscribe, you’ll never mess with confusing settings and options menus again; just turn it on on your desktop once, and it’s good to go in the background forever.

  • Mask your physical location from 3rd parties w/ an encrypted tunnel
  • Access geo-locked content from anywhere
  • Avoid most ads while you’re browsing
  • Torrent securely & share files w/o worrying about your ISP snooping on you
  • Use on all your devices simultaneously
  • Get protected by the top-notch firewall that protects you in case of connectivity loss
  • Leave no trace or logs while you browse

MacTrast Deals: Windscribe VPN Sale: 1 Year, 3 Year, 5 Year, and Lifetime Subscription

SPECS

Details & Requirements

  • Version 1.58
  • Unlimited devices
  • Updates included

Compatibility

  • Windows XP, Vista, 7, 8, 10
  • OS X 10.8 or later
  • Linux
  • iOS
  • Android app coming soon

Terms

  • Instant digital redemption

LICENSE

  • Length of access: Lifetime, 5 years, 3 years, 1 year depending on subscription
  • Updates included
  • Unlimited data
  • Unlimited devices

Windscribe VPN: Lifetime Pro Subscription – Hello, Private Browsing! Protect Your Browser & Your Desktop with This Complete VPN – $39.99, With Coupon Code: windscribesd20

Windscribe VPN: 5 Year Pro Subscription – Hello, Private Browsing! Protect Your Browser & Your Desktop with This Complete VPN – 5-YR Subscription: $29.99, With Coupon Code: windscribesd25

Windscribe VPN: 3 Year Pro Subscription – Hello, Private Browsing! Protect Your Browser & Your Desktop with This Complete VPN – 3-YR Subscription: $19.99, With Coupon Code: windscribesd11

Windscribe VPN: 1 Year Pro Subscription – Hello, Private Browsing! Protect Your Browser & Your Desktop with This Complete VPN – 1-YR Subscription: $19.99

Wallpaper Weekends: Yosemite Tunnel View for Mac, iPad, iPhone, and Apple Watch

Wallpaper Weekends is a series that works to bring you stunning, high-quality wallpapers for your iPad, iPhone, iPod touch, Mac, and Apple Watch.

“Yosemite Valley, to me, is always a sunrise, a glitter of green and golden wonder in a vast edifice of stone and space.” – Ansel Adams

This week’s wallpaper comes from Unsplash – They have a HUGE collection of free, high-resolution photos. For 10 free new photos every 10 days, subscribe at Unsplash. This photo is from photographer James Donovan.

Mac

Wallpaper Weekends: Yosemite Tunnel View for Mac, iPad, iPhone, and Apple Watch

 

iPad

Wallpaper Weekends: Yosemite Tunnel View for Mac, iPad, iPhone, and Apple Watch

iPhone

Wallpaper Weekends: Yosemite Tunnel View for Mac, iPad, iPhone, and Apple Watch

Apple Watch

Download Directions for iPhone and iPad

From your device, link to the full resolution image by tapping the individual images. When the new window opens, tap the Safari Extensions icon in the bottom area of your browser, (it looks like a box with an up arrow sticking out of it), and tap “Save image” to save the image to your Photo Library.

From your desktop computer, link to the full resolution image by clicking the image. Right-click and save the image to your iTunes photo sync folder.

Download Directions for Apple Watch

From your iPhone, link to the full resolution image by tapping the individual images. When the new window opens, tap the Safari Extensions icon in the bottom area of your browser, (it looks like a box with an up arrow sticking out of it), and tap “Save image” to save the image to your Photo Library.

After you’ve saved all of the wallpapers you’d like to use, open the Photos app on your iPhone and move the new images to the album you use to share images with you Apple Watch. Now you can go to your Apple Watch, select the new wallpaper as a watch face, and customize it to your heart’s content. If you do download several of the wallpapers and move them to your Watch, you can even set them to rotate between them each time you view your watch face!

Download & Installation Instructions for the Mac

From your Mac, click your mouse pointer on one of the images. When the full-sized image appears in your browser, right-click or CTRL-Click on the image, and click on “Save Image As…” to save the image to your Mac’s hard drive.

Now, right-click or CTRL-click on your desktop, and select “Change Desktop Background…” In the Desktop & Screen Saver dialog box that appears, click the “+” button at the bottom of the left panel. Navigate to the directory you saved the wallpaper in, and double-click the wallpaper filename.

Or, as reader Biff Bifferson pointed out, you can just right-click on the image in the browser and click “Set As Desktop Background.” That both changes the desktop AND saves the image.

Page 1 of 244

Powered by WordPress & Theme by Anders Norén