Need to insert text(constant) at the beginning of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to insert text(constant) at the beginning of file
# 1  
Old 06-23-2012
Need to insert text(constant) at the beginning of file

I am very new to scripting and I know this request is simple but I am having no luck with it.

I have a file a.dat with the following data in it.
aa
bb
cc
dd

I need to run a script that will take each line of a.dat and put dsjc/ubin/ in front of each record, so the output looks like

dsjc/ubin/aa
dsjc/ubin/bb
dsjc/ubin/cc
dsjc/ubin/dd

Thanks in advance for your help.
# 2  
Old 06-23-2012
Code:
sed 's+^+dscj/ubin/+' a.dat

the caret ^ matches beginning of the line, + is a delimiter, can be any char that is not in the pattern.
# 3  
Old 06-24-2012
Awesome!!!!!!!!!!!
Thanks so much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use sed to insert character in the beginning of file path?

I need to manipulate one Database file on Solaris 11 in which contains more than 5000 lines of data file path like this: '/data1/oradata/DBNAME/system01.dbf', '/data7/oradata/DBNAME/undotbs1_01.dbf', '/data1/oradata/DBNAME/sysaux01.dbf', '/data28/oradata/DBNAME/userdata01.dbf', ... (6 Replies)
Discussion started by: duke0001
6 Replies

2. UNIX for Advanced & Expert Users

Insert a column in the beginning

Hi, I have been trying to see how i can insert a column in the beginning to my html table This is how it looks Name Age Sid 32 John 33 Mary 34 I want to insert a column Job before Name column, so it looks like Job Name Age IT Sid 32 Doctor... (3 Replies)
Discussion started by: sidnow
3 Replies

3. Shell Programming and Scripting

Insert text at the beginning of every even number line

i am trying to insert text at the beginning of every even number line with awk i can do it with odd number lines with this command awk 'NR%2{$0="some text "$0}1' filehow can i edit this command thanks (5 Replies)
Discussion started by: bob123
5 Replies

4. Shell Programming and Scripting

Insert output from a file to beginning of line with sed

Hi I've been trying to search but couldn't quite get the answer I was looking for. I have a a file that's like this Time, 9/1/12 0:00, 1033 0:10, 1044 ... 23:50, 1050 How do I make it so the file will be like this? 9/1/12, 0:00, 1033 9/1/12, 0:10, 1044 ... 9/1/12, 23:50, 1050 I... (4 Replies)
Discussion started by: diesel88
4 Replies

5. Shell Programming and Scripting

Insert at the beginning of odd lines

Hello people, I am trying with sed to insert some text at the beginning of each odd line of a file but no luck. Can you please help. Awk is also suitable but I am not very familiar with it. Thank you in advance for any help. (7 Replies)
Discussion started by: drbiloukos
7 Replies

6. Shell Programming and Scripting

Howto add a constant column to the text file

Hi, I am converting a .DBF file to pipe delimited file my requirement is like lets say my .DBF is residing in path /a/b/c/d/f/abc.DBF I need my .txt file as having a column with source _cd =f sample data in .DBF in folder "f" c1 c2 c3 1 2 3 in txt file it should be... (4 Replies)
Discussion started by: angel12345
4 Replies

7. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

8. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

9. Shell Programming and Scripting

Insert two strings at the beginning and at the end of each line of a file

Hi, excuse me for my poor english. My problem is that: I have a File i want to add to each line of that file two strings: one at the beginning of the line, one at the ending. string1="abcd" string2="efgh" i want $string1 content $string2 for each line. Is that possible? (3 Replies)
Discussion started by: Linux-fueled
3 Replies

10. Shell Programming and Scripting

Add text to beginning of file

Hi I need to add text to the beginning of a file in the same way that cat will put file contents at the end of a file. I want to do this with many files eg cat newtext >> /usr/home/*/*.bat Any ideas? (2 Replies)
Discussion started by: donkey
2 Replies
Login or Register to Ask a Question