add a line to a specfic point in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers add a line to a specfic point in a file
# 1  
Old 12-07-2006
add a line to a specfic point in a file

Hello,

Simple if you know how, which I don't....

I would like to add a line to file file.env

file.env consists of the following :

line 1-20 here ..
# Begin customizations

$AVARIABLE/dir1/dir2;export $AVARIABLE

# End customizations
eof

I would like to use a shell script to add the line $AVARIABLE/dir1/dir2;export $AVARIABLE, but it has to come after # Begin customizations

Any idea how to do this please ? Thanks for your time.

Cheers,
Dave
# 2  
Old 12-07-2006
Try this AWK command, It should work

awk '{if ($1 == "#" && $2 == "Begin" && $3 == "customizations" && NF == 3) $NF=$NF"\n$AVARIABLE/dir1/dir2;export $AVARIABLE"; print }' file_name

Have fun
# 3  
Old 12-08-2006
great thanks, that works a treat.
 
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 create a new mount point with 600GB and add 350 GBexisting mount point? IN AIX

How to create a new mount point with 600GB and add 350 GBexisting mount point Best if there step that i can follow or execute before i mount or add diskspace IN AIX Thanks (2 Replies)
Discussion started by: Thilagarajan
2 Replies

2. UNIX for Dummies Questions & Answers

Trying To Write File Contents To Specfic .csv Cell

Hi, I'm attempting to write the entire contents of a file to a specific .csv cell. So far have only a nawk one liner that will write a value into a specific .csv cell. Trying to use man page but can't seem to get any farther. Any help would be appreciated. nawk -v r=2 -v c=3 -v val=5 -F,... (7 Replies)
Discussion started by: jimmyf
7 Replies

3. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

4. UNIX for Dummies Questions & Answers

Add floating point numbers from file

How do I use bash to add all the floating point numbers saved in a file like this? 490.47 244.61 263.07 131.59 246.81 115.20 (3 Replies)
Discussion started by: locoroco
3 Replies

5. Shell Programming and Scripting

To track any modification in a specfic file

Hi All, I am a pretty new to programming or scripting. Please help me in my below query. I want to write a script which can track a file for any kind of modification and if there is any modification then it should move that file or i should say backup that file to another server. Please... (6 Replies)
Discussion started by: makkar4u
6 Replies

6. Shell Programming and Scripting

howto add line as a first line into a non empty file

Hi Trying to do like this : echo "$variable1\n $(cat file.txt)" but it only adds one time. When I run this cmd again with different variable it only replaces line of variable1. How to add constantly line into first line in file ? (3 Replies)
Discussion started by: presul
3 Replies

7. Shell Programming and Scripting

Add new parameters into a line, and redirect the line to other file

How can i add new parameters into a line, and redirect the line to other file? For example: 1.sh name:owner google:richard youtube:student I want a, for example 2.sh with: name:owner:description google:richard:search site youtube:student:video site In the 2.sh, I added a new column:... (7 Replies)
Discussion started by: rafazz
7 Replies

8. Shell Programming and Scripting

Every nth line with different starting point

Hi every one, I am trying to generate different files from a column of numbers with the following format, as an example: main file(input) 1 2 3 . ... (19 Replies)
Discussion started by: nxp
19 Replies

9. UNIX for Dummies Questions & Answers

Delete line till certain point

Hi, I have a requirement to delete a line till a certain word. Am not sure how to do it e.g I want to delete till the bold character since start of line. Any help is higly appretiated. (2 Replies)
Discussion started by: inq
2 Replies

10. Shell Programming and Scripting

add a line to a specfic point in a file

Hello, Simple if you know how, which I don't.... I would like to add a line to file file.env file.env consists of the following : line 1-20 here .. # Begin customizations $AVARIABLE/dir1/dir2;export $AVARIABLE # End customizations eof I would like to use a shell script to... (4 Replies)
Discussion started by: d__browne
4 Replies
Login or Register to Ask a Question