Last active
January 28, 2018 20:45
-
-
Save rodrigobdz/188d43beeb4db4ab0f78910d80918fcf to your computer and use it in GitHub Desktop.
Replace line in text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (C) 2017 Rodrigo Bermudez Schettino | |
# Script to replace a line in a text file | |
# Create file with sample text | |
echo "this will be replaced" > file.txt | |
############ | |
# file.txt # | |
############ | |
# this will be replaced | |
LINE_NUMBER=1 | |
CONTENT="foo" | |
# It takes as an argument the line to replace and the content | |
# to insert as a replacement | |
sed -i "${LINE_NUMBER}c\\${CONTENT}" file.txt | |
############ | |
# file.txt # | |
############ | |
# foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace line in text file
Example on how to replace a specific line in a file by number.
Usage