RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

Add character to the beginning of each line using sed

This example shows how to add a character to the beginning of each line using a sed command and bash shell.
Let's create example file.txt with some text:

add 
character
at the
beginning of
each line

Add character at the beginning of each line using sed command. For example to add # in front of each line we can use sed command with following syntax:

$ sed 's/^/#/' file.txt
#add
#character
#at the
#beginning of
#each line

replace # with ' ' ( space ) to add space in front of each line:

$ sed 's/^/ /' file.txt
 add
 character
 at the
 beginning of
 each line

Redirect the output produced by sed command to save it to a file:

$ sed 's/^/ /' file.txt  > new-file.txt
$ cat new-file.txt
 add
 character
 at the
 beginning of
 each line

Share this linux post:

Submit Add character to the beginning of each line using sed in Delicious Submit Add character to the beginning of each line using sed in Digg Submit Add character to the beginning of each line using sed in FaceBook Submit Add character to the beginning of each line using sed in Google Bookmarks Submit Add character to the beginning of each line using sed in Stumbleupon Submit Add character to the beginning of each line using sed in Technorati Submit Add character to the beginning of each line using sed in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download