How to add a prefix string at the beginning of each line in Bash shell script on Linux?

How to add a prefix string at the beginning of each line in Bash shell script on Linux?

For example, assume we have a file a.txt:

line 1
line 2

I want to have,

pre line 1
pre line 2

You may use sed, the stream editor for filtering and transforming text:

sed -e 's/^/pre /'

For example,

$ echo "line 1
line 2" | sed -e 's/^/pre /'
pre line 1
pre line 2

You may also do prefix adding to lines of certain patterns. But this is out of this question.

Similar Posts

  • SQL layers on NoSQL databases

    What are the SQL layer solution over NoSQL databases such as key/value stores? Phoenix: A SQL layer on HBase: https://github.com/forcedotcom/phoenix They also show some performance results: https://github.com/forcedotcom/phoenix/wiki/Performance F1 – The Fault-Tolerant Distributed RDBMS Supporting Google’s Ad Business: http://research.google.com/pubs/pub38125.html With F1, we have built a novel hybrid system that combines the scalability, fault tolerance, transparent sharding,…

  • Designing posters – SysTutorials QA

    Some tutorials or materials for designing posters? Designing conference posters by Colin Purrington: http://colinpurrington.com/tips/academic/posterdesign Scribus – an open source desktop publishing tool: http://www.scribus.net/canvas/Scribus Inkscape is a good tool for editing vector figures. GIMP is a great tool for editing images. Read more: Squeezing Space in LaTeX – SysTutorials QA Free server images – SysTutorials QA…

  • | |

    Release Notes For Linux v2.0

    This is the release notes for linux release v2.0 (source code: linux-2.0.tar.gz) with format adjusted by removing/replacing tabs/spaces/new lines/formatting marks. This notes document can give us an understanding of the early development of the Linux kernel. The original ASCII formatted version is at the end of this post. Intro This document contains a list of…

  • rtl8192cu driver for CentOS 7

    I find the rtl8192cu wireless adapter driver on CentOS 7 is quite unstable. After running a while, the connection will disappear. How to make it stable? There is a bug in some hardware where the device never wakes back up. You may try disabling the power management by putting a file 8192cu-disable-power-management.conf under /etc/modprobe.d/: #…

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *