Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.pages
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ nav:
- Guides: guides
- Books: books
- Labs: labs
- Gemstones: gemstones
- Release Notes: release_notes
- Rocky Linux: https://rockylinux.org
20 changes: 20 additions & 0 deletions docs/gemstones/index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Index
author: Steven Spencer
---

# Gemstones

Welcome to **Gemstones**! I can hear you now: _"What on earth are Gemstones, and how do they fit into Rocky Linux documentation?"_ That is a very good question. While **Guides** contains our normal length how-to documentation and **Books** contain our longer-form documentation, **Gemstones** are just little gems of wisdom. Have a favorite bit of Linux code that you use all the time or a favorite command? Maybe you've written a script in `bash`, `python`, or other common Linux language, that you would like to share because it helps you in your day-to-day use of Linux? If any of these things are true, **Gemstones** is the place for your contribution!

## Criteria

Your code, script, or command document should be short. If it is many pages long, then it belongs elsewhere in the documentation. We are looking for a page or possibly two. In order for your "gemstone" to be complete, we suggest including:

* A good description
* Any reasons why you do things a particular way, in the case of a script
* A brief conclusion

## Contribution

You can contribute your **Gemstone** in the same way that you contribute other documentation (see: [Guides/Contribution/Contribution Guide](../guides/contribute/README.md)). When you submit a pull request to GitHub, include "gemstone" in the commit message. If you don't have or don't want a GitHub account, you can simply submit it to the [Mattermost Documentation channel](https://chat.rockylinux.org/rocky-linux/channels/documentation) and we will edit and create your **Gemstone** for you. It couldn't be easier!
36 changes: 36 additions & 0 deletions docs/gemstones/perl_search_replace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Perl - Search and Replace
author: Steven Spencer
---

# `perl` Search and Replace

Sometimes you need to quickly search and replace strings in a file or group of files. There are many ways to do this, but this method uses `perl`

To search for and replace a particular string across multiple files in a directory, the command would be:

```
perl -pi -w -e 's/search_for/replace_with/g;' ~/Dir_to_search/*.html
```
For a single file that might have multiple instances of the string, you can specify the file:

```
perl -pi -w -e 's/search_for/replace_with/g;' /var/www/htdocs/bigfile.html
```

This command uses vi syntax for search and replace to find any occurrence of a string and replace it with another string across a single or multiple files of a particular type. Useful for replacing html/php link changes embedded in those types of files, and many other things.

## Options Explained

|Option | Explanation |
|-------|---------------------------------------------------------------|
| p | places a loop around your script |
| i | edit file in place |
| w | prints out warning messages in case something goes wrong |
| e | allows a single line of code entered on the command line |
| s | specifies search |
| g | specifies to replace globally, in other words all occurrences |

## Conclusion

A simple way to replace a string in either one or many files using `perl`.