Sed Script Problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed Script Problem
# 1  
Old 05-26-2009
Java 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  
Old 05-26-2009
use awk
Code:
# awk 'BEGIN{RS=""}!/AND1 \(A|B\)/' file
AND1 (C) {
non : hafe3
on: tc2
ma : nite3 }

# 3  
Old 05-26-2009
Java 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk script problem

Hi All I am having a file as shown below File1# modyle 1 { test jsj hhsjh 13e3 jsjjs } memP(dbg_trace) { ajjs jsjs jsjs Test(claer) { jsjs (7 Replies)
Discussion started by: kshitij
7 Replies

2. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

3. Shell Programming and Scripting

Problem removing $ using sed in script

I am trying to use the sed command to remove any character that is passed as a parameter to the script. I may want to replace any character in the file (-, =, $, space). I'm running into an issue when passing the $. This is a typical row in the file. "000000B553","--INTERNAL USE... (6 Replies)
Discussion started by: nadneb
6 Replies

4. Shell Programming and Scripting

Problem using sed

Hi Guys, I have been using sed command to find anything between double quotes. But I also have to incorporate something that first checks for single or double quotes and accordingly sed command should be used. Example: set x = '""A""' echo $x | sed 's/.*""\(.*\)"".*/\1/' Answer: A... (4 Replies)
Discussion started by: dixits
4 Replies

5. Shell Programming and Scripting

Shell Script problem with sed

Hello i have a shell script which will go in some folders using for loop, build some programs with gcc and zip the output. then i have to paste the file of that zip file into a yml file which will be further used by a ruby watir script. PROJECT_PATH=/uploads/$PROJECT_FOLDER zip -rq ... (0 Replies)
Discussion started by: vikki1986
0 Replies

6. Shell Programming and Scripting

Problem using sed in script

Hey guys, I'm looking to write a script that takes a variable line number and prints that line via sed, but I'm having an issue with the syntax. As I understand it, the sed syntax to print line number 52 (for example) is as follows: sed -n '52p' sed '52!d' sed '52q;d' But how can you... (2 Replies)
Discussion started by: wandergeek
2 Replies

7. Shell Programming and Scripting

sed problem

hi all i want to use sed command to replace check_Switch2!192.168.1.1!10.0.0.1 to check_by_nrpe!10.0.0.1!check_AP!192.168.1.1 thanks in advance (1 Reply)
Discussion started by: bondoq
1 Replies

8. Shell Programming and Scripting

Sed problem

Hi guys, I have a problem where by I need to remane a file by moving it to another location. For instance I have a file called change.txt changeA.txt changeB.txt and I need to change the name to change_a1.txt changeA_a2.txt changeB_a3.txt I need a sed regular expression that changes... (3 Replies)
Discussion started by: abch624
3 Replies

9. Shell Programming and Scripting

problem with sed command in shell script.

Guys, I've a problem in the "sed" command used in my shellscripts This is the problamatic line in my shell script: sed -e 's/${line1}/${line1_m}/g' prod_hier_1234.txt > test.txt It doesn't do the job of replacing the string stored in variable 'line1' to 'line1_m'. However If I replace the... (10 Replies)
Discussion started by: bhagat.singh-j
10 Replies

10. UNIX for Dummies Questions & Answers

sed modify problem in script

I am having problems with the following "sed" command only when it is issued within a bash script. #!/bin/bash cat config.xml | sed -e 's/yes/no/g' > newconfig.xml When I enter this command from the command line it works like a charm, but when run in a script as shown it "zero's out" my... (2 Replies)
Discussion started by: darthur
2 Replies
Login or Register to Ask a Question