The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
call shell script from perl cgi script problem raksha.s Shell Programming and Scripting 2 03-25-2009 04:50 AM
ssh script problem problem pcjandyala Shell Programming and Scripting 2 07-31-2008 03:27 PM
One more problem with script syndex Shell Programming and Scripting 4 07-11-2007 04:48 PM
awk script Problem pbsrinivas Shell Programming and Scripting 6 07-05-2007 10:04 AM
Problem starting a script from a 'main'-script Rakker UNIX for Dummies Questions & Answers 3 06-28-2005 08:12 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-26-2009
shalini_008 shalini_008 is offline
Registered User
  
 

Join Date: May 2009
Posts: 4
Post Sed Script Problem

My file is having the contents like this

AND1 (A) {
non : hafe
on: tc
ma : nite }

AND1 (B) {
non : hafe1
on: tc1
ma : nite1 }

AND1 (C) {
non : hafe3
on: tc2
ma : nite3 }


I have written a sed script to search the patterns AND1(A) and AND1 (B) and delete the entire content in these Blocks including the Patters AND1 (A) and AND1 (B)

but to my surprise the whole file content is getting deleted

This is my sed script

sed -n '/AND1 (A)/,/AND1 (B)/ { /non/d ;}'file > file1

My new file content should be

AND1 (C) {
non : hafe3
on: tc2
ma : nite3 }

but the whole file is getting deleted

Can someone give me advice ?
  #2 (permalink)  
Old 05-26-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,518
use awk
Code:
# awk 'BEGIN{RS=""}!/AND1 \(A|B\)/' file
AND1 (C) {
non : hafe3
on: tc2
ma : nite3 }
  #3 (permalink)  
Old 05-26-2009
shalini_008 shalini_008 is offline
Registered User
  
 

Join Date: May 2009
Posts: 4
Post awk script Issues

Thanks actually that soultion actually worked .

I am having another issue with my awk script

Contents of my file is like this
file
AND (P1) {
no : and ;
mo : band ;
co : land ;
}

OR (P2) {

no : sand ;
cling : dad ;
Fiend : salt ;

}

NAND (P3)

no : sat ;
to : jat;
pi : tad;
}


What I need to do I need to search the patterns AND (P1) and OR (P2) and then delete all the contents of this Block and insert the content from another file - file2 ( between P1 and P2 ) in this location.


What I am doing ; I am inserting the code first


awk '{ if($0 ~ /P1/) {set=1; next}; if( $0 ~ /P2/) {set = 0}; if (set ) { print }}' file2 | awk '/AND (P1)/{f=1}f && /}/{print; system("cat $1");f=0;next}1' file > newfile

file2 content
############
P1

AND is the the band
land is the and

P2

#############

After this To delete the blocks I could use
sed '/AND/,/OR/d' file

I am having two issues here
1. The code will be inserted after the AND (P1) Block I want the code to be inserted before AND (P1) Block so that I can delete the respective blocks after that
2. By using the command sed '/AND/,/OR/d' file
I will delete not full contents
It will delete only these entities

AND (P1) {
no : and ;
mo : band ;
co : land ;
}

OR (P2) {


Need some advice in this regards

Shalini
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 On




All times are GMT -4. The time now is 11:27 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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0