Need sed command with an exception

All,

I am currently using the below code to add a line /var/temp/'$input1'/permissions

Below is the shell ::

sed '
/Unix_command/ a\
unix: /var/temp/'$input1'/permissions' temp1.txt> temp2.txt

above will add the line below Unix_command word

unix: /var/temp/'$input1'/permissions where as input 1 == unixid to all in the output file (temp2.txt) .

But i dont need to add the lines to certain lines in that file .. can you provide me the shell which can exclude the above line when i am passing it using a Parameter file .

Basically it should read from the parameter file and it should not add the line to the output file (temp2.txt)

Example :: if the parameter file has a word unix_dump

then it should not add the line to the output file . Below is the example ::

unix_dump=a
Unix_command=s

Please Note :: Unix_command is a command word and it will be there in the input file (temp1.txt) .

Thanks for your Help ..

Raghav

why don't you try awk instead of sed?

awk '/searchpattern/{print "inserted text";print;next}1'  file

i tried to use the same.. but didnot work according to my condition.

Thanks!

I tried to fix the code, but not able to get the results. can anyone help me on this ???

Post your input file, the file with the parameters and the expected output.

more param.txt

unix_dump

more temp.txt[[[ which is the input file ]]]

unix_core=a 
unix: /var/temp/unixid/permissions


unix_dump=c
unix: /var/temp/unixid/permissions

Expected Output ::

unix_core=a 
unix: /var/temp/unixid/permissions
Unix_command 

unix_dump=c
unix: /var/temp/unixid/permissions

=======================================

It should not add the word Unix_command which are mentioned in the Param file. The below which i am using will add the word to all

sed '
/Unix_command/ a\
unix: /var/temp/unixid/permissions' temp1.txt> temp2.txt

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

With the given files this should work:

awk 'NR==FNR{s=$0;next}
/unix: \/var\/temp\/unixid\/permissions/ && !f {$0=$0 RS s;f=1}
{print}' param.txt temp.txt