Sponsored Content
Full Discussion: Sed Script Problem
Top Forums Shell Programming and Scripting Sed Script Problem Post 302319764 by shalini_008 on Tuesday 26th of May 2009 06:42:11 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
CAT(1)							    BSD General Commands Manual 						    CAT(1)

NAME
cat -- concatenate and print files SYNOPSIS
cat [-benstuv] [file ...] DESCRIPTION
The cat utility reads files sequentially, writing them to the standard output. The file operands are processed in command-line order. If file is a single dash ('-') or absent, cat reads from the standard input. If file is a UNIX domain socket, cat connects to it and then reads it until EOF. This complements the UNIX domain binding capability available in inetd(8). The options are as follows: -b Number the non-blank output lines, starting at 1. -e Display non-printing characters (see the -v option), and display a dollar sign ('$') at the end of each line. -n Number the output lines, starting at 1. -s Squeeze multiple adjacent empty lines, causing the output to be single spaced. -t Display non-printing characters (see the -v option), and display tab characters as '^I'. -u Disable output buffering. -v Display non-printing characters so they are visible. Control characters print as '^X' for control-X; the delete character (octal 0177) prints as '^?'. Non-ASCII characters (with the high bit set) are printed as 'M-' (for meta) followed by the character for the low 7 bits. EXIT STATUS
The cat utility exits 0 on success, and >0 if an error occurs. EXAMPLES
The command: cat file1 will print the contents of file1 to the standard output. The command: cat file1 file2 > file3 will sequentially print the contents of file1 and file2 to the file file3, truncating file3 if it already exists. See the manual page for your shell (i.e., sh(1)) for more information on redirection. The command: cat file1 - file2 - file3 will print the contents of file1, print data it receives from the standard input until it receives an EOF ('^D') character, print the con- tents of file2, read and output contents of the standard input again, then finally output the contents of file3. Note that if the standard input referred to a file, the second dash on the command-line would have no effect, since the entire contents of the file would have already been read and printed by cat when it encountered the first '-' operand. SEE ALSO
head(1), more(1), pr(1), sh(1), tail(1), vis(1), zcat(1), setbuf(3) Rob Pike, "UNIX Style, or cat -v Considered Harmful", USENIX Summer Conference Proceedings, 1983. STANDARDS
The cat utility is compliant with the IEEE Std 1003.2-1992 (``POSIX.2'') specification. The flags [-benstv] are extensions to the specification. HISTORY
A cat utility appeared in Version 1 AT&T UNIX. Dennis Ritchie designed and wrote the first man page. It appears to have been cat(1). BUGS
Because of the shell language mechanism used to perform output redirection, the command ``cat file1 file2 > file1'' will cause the original data in file1 to be destroyed! The cat utility does not recognize multibyte characters when the -t or -v option is in effect. BSD
March 21, 2004 BSD
All times are GMT -4. The time now is 04:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy