CodeRef
CodeRef
  • Software
    • VSCode
  • Midjourney_AI
    • Midjourney Cheat Sheet
  • aws
    • S3 Reference
    • Services
  • bash
    • .bashrc File Contents
    • CAN
    • _System Config File Locations
    • argument-length-limits
    • Conditionals
    • Data Structures
    • File Permissions
    • File Syncing
    • File System
    • Functions
    • General
    • Loops
    • My Functions
    • Networking
    • Number Operations
    • OpenVPN
    • Operators
    • Resource Management
    • Serial RS232
    • Spinning Wheel Animation
    • SSH
    • Text Operations
    • Environment Variables
  • cpp
    • ChatGPT | Pointers vs. References
    • arrays
    • Classes
    • Data Types / Structures
    • Enumerated Classes
    • Exception Handling
    • Function Objects
    • Functions
    • I/O
    • Loops
    • Macros
    • Namespaces
    • New Features
    • Pointers
    • Scope
    • Smart Pointers
    • Raw String Literals
    • Style Guide
    • Switch Case
    • Templating
    • How to Use tinyxml2
    • Useful Libraries
    • google-test
    • Conditionals
    • Rule of Three/Five
    • Optional Parameters
    • Keywords
    • Filesystem
    • Random
    • Casting
    • tools
  • git
    • Code Review Dependency Strategy
    • Git Bisect Guide
    • Git Reference
    • removing-cherry-picks
    • Useful Tools
    • Graphite Reference
  • js
    • functions
    • Javascript Reference
  • linux
    • Display
    • Dual Boot with Windows
    • File System
    • NVIDIA
    • Sending/Receiving TCP/UDP Messages in Ubuntu
    • dynamically_linked_binaries
  • markdown
    • Images
    • obsidian-reference
  • python
    • Classes
    • Exceptions
    • Functions
    • Operations
    • Python Reference
    • unittest_command-line-args
    • unittest_magicmock_GPT
    • unittest_mock
    • unittest_printing
    • unittest_subtest
    • useful-stuff
    • jupyter
    • poetry
  • ros
    • _ROS Cheat Sheet
    • Create New Workspace
    • Install ROS
    • Node Sample - Listener
    • Node Sample - Talker
    • Node Template
    • Setup
    • urdf
  • excel
    • excel-reference
  • windows
    • File System
    • WSL - Windows Subsystem for Linux
    • WSL
  • software_engineering
    • uncle_bob_lectures
      • Overview
      • Lesson 01 - Notes
  • web
    • Front End
    • Hugo
    • new_frontend_tools
  • sql
    • cheatsheet
Powered by GitBook
On this page
  1. bash

Text Operations

# String Concatenation:
x="hello"
y="world"
echo $x$y	# Prints "helloworld"
echo $y$x	# Prints "worldhello"
# Substrings:
x="hello"
echo ${x:0:3}	# Prints "hel" (3 chars starting at char 0)
echo ${x:3}		# Prints "lo" (char 3 through end)
# Find and replace within string:
${main_string/search_term/replace_term}	# First occurrence only.
${main_string//search_term/replace_term}	# All occurrences.
# Special characters:
n=$'\n'	# newline
t=$'\t'	# tab
r=$'\r'	# carriage return
# Get length of string:
str="hello"
echo ${#str}
# Grep:
grep -i "literal"	# return lines containing 'literal', case insensitive
grep -v "hello"		# return lines NOT containing 'hello', case sensitive
grep -E "hello|world|pizza"	# return lines containing 'hello' OR 'world' OR 'pizza'
grep "he..owo..d"	# return lines containing he, owo, d with anything in between (. is wildcard)
	# Examples = helloworld, heppowoeed, hekkowossd, etc.
grep "AB[CDE]HI[JKL]"	# returns lines containing any character in brackets in those positions
	# Examples = ABCHIJ, ABDHIJ, ABEHIL, etc.

Last updated 2 years ago