Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-21-2009
Registered User
 

Join Date: Sep 2007
Posts: 101
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
Sponsored Links
  #2 (permalink)  
Old 06-21-2009
Registered User
 

Join Date: Sep 2006
Posts: 2,604
why don't you try awk instead of sed?

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

  #3 (permalink)  
Old 06-26-2009
Registered User
 

Join Date: Sep 2007
Posts: 101
i tried to use the same.. but didnot work according to my condition.

Thanks!
  #4 (permalink)  
Old 07-06-2009
Registered User
 

Join Date: Sep 2007
Posts: 101
Quote:
Originally Posted by ghostdog74 View Post
why don't you try awk instead of sed?

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

I tried to fix the code, but not able to get the results. can anyone help me on this ???
  #5 (permalink)  
Old 07-06-2009
Moderator
 

Join Date: Feb 2007
Location: The Netherlands
Posts: 4,962
Post your input file, the file with the parameters and the expected output.
  #6 (permalink)  
Old 07-06-2009
Registered User
 

Join Date: Sep 2007
Posts: 101
Quote:
Originally Posted by Franklin52 View Post
Post your input file, the file with the parameters and the expected output.


more param.txt

Code:
unix_dump

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

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


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


Expected Output ::
======================================

Code:
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


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


Last edited by vgersh99; 07-06-2009 at 05:31 PM.. Reason: code
Bits Awarded / Charged to raghav1982 for this Post
Date User Comment Amount
07-06-2009 vgersh99 added code tags - charged 10K bits -10,000
  #7 (permalink)  
Old 07-06-2009
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,199
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 [code] and [/code] 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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Exception Handling bertpereira Shell Programming and Scripting 5 01-14-2009 09:28 PM
Handling "command not found" exception nsharath Linux 5 12-18-2008 03:29 AM
MMU exception Puntino Linux 2 05-07-2008 01:35 PM
Help with RPC Exception ejbrever HP-UX 2 08-24-2006 03:08 PM
RPC Exception - Help ejbrever UNIX for Advanced & Expert Users 0 08-21-2006 01:56 PM



All times are GMT -4. The time now is 03:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0