Home
Man
Search
Today's Posts
Register

All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

Trying to add text to the beginning of each line

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 07-01-2012
Trying to add text to the beginning of each line

Well here goes:

I tried to write a batch file that adds a specific fixed text to each line of an already existing text file.

for the adding text infront of each line I tried this:

Code:
for /F "delims=" %%j in (list.txt) do echo.STARTTEXT\%%j >> list.txt

for adding text after each line I haven't figured out how to do it.


HOWEVER:

When I use the code descripted, this:

Code:
1stline

becomes this ->>>
Code:
1stline
STARTTEXT1stline

I want it to be just
Code:
STARTTEXT1line

so to sum it up I want to add something BEFORE and AFTER the 1line (for each line in a text file), like this:

Code:
STARTTEXT1stlineENDTEXT
STARTTEXT2ndlineENDTEXT
STARTTEXT3rdlineENDTEXT
...

Any help is appreciated
# 2  
Old 07-01-2012
use the below script to add text infront of each line :

sed 's/^/STARTTEXT/g' filenmae > output_file
# 3  
Old 07-01-2012
Please note: This question is in the "Windows & Dos..." forum. A Unix-like answer may not be appropriate here.

Having said that, and in the absence of a batch script answer, sed is available for Windows:

sed for Windows
# 4  
Old 07-01-2012
so... without sed it is impossible ?
# 5  
Old 07-01-2012
With Windows scripting, it always helps to mention the exact version of Windows and whether you have installed any extended Windows scripting products and whether you have any programming languages installed.
# 6  
Old 07-02-2012
Well I got Windows 7 Ultimate 32 bit.

No additional extended scripting products installed.

if sed is the only way I'd take an example for that aswell.

Thanks
# 7  
Old 10-18-2012
The issue is that you are attempting to read the same file as you are writing. You can go ahead and use the code you wrote but instead of writing to the same file, write to a temporary file and then copy it over the original file

Code:
for /F "delims=" %%j in (list.txt) do echo.STARTTEXT\%%j >> tempfile.txt
 
followed by 
copy /Y tempfile.txt list.txt

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Insert text at the beginning of every even number line bob123 Shell Programming and Scripting 5 04-04-2016 03:01 PM
Adding a text in the beginning of a line Saanvi1 Shell Programming and Scripting 7 01-28-2014 02:11 AM
How to add a text at the beginning of a text files in a folder? suryanarayana Shell Programming and Scripting 3 09-24-2013 04:09 PM
beginning less from line # IMPe Shell Programming and Scripting 2 09-18-2012 12:08 PM
comment a line of the patterns is a the beginning of the line anil510 Shell Programming and Scripting 9 08-27-2012 10:22 AM
vim copy line and paste at the beginning, middle, and end of another line cokedude UNIX for Dummies Questions & Answers 3 07-16-2012 06:38 PM
trying to add text to beginning and end of each line pasc Shell Programming and Scripting 0 07-01-2012 08:36 AM
How to specify beginning-of-line/end-of-line characters inside a regex range jawsnnn UNIX for Dummies Questions & Answers 3 06-20-2012 02:31 PM
Add text to beginning of file donkey Shell Programming and Scripting 2 08-24-2007 08:24 AM
Unix Script with line number at beginning of each line. mascorro Shell Programming and Scripting 5 06-19-2006 05:34 PM


All times are GMT -4. The time now is 02:56 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password