Substitution of char with AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substitution of char with AWK
# 1  
Old 06-13-2007
Substitution of char with AWK

I created a file contains:

create table .....;
create index ....;
create trigger...;

and I want to substitue from my file ; by ;-- from the line where appears create trigger to the end of the file and keep intact the create table step and index in the file.


awk '/CREATE TRIGGER/,/END;/ { gsub(/;/, ";--") print} ' db2look.bk > toto
# 2  
Old 06-13-2007
Bug

Below should work:

awk '/create trigger/{gsub(/;/, ";--")};{print}' my_file > my_file_out
# 3  
Old 06-13-2007
Quote:
Originally Posted by mario dionne
I created a file contains:

create table .....;
create index ....;
create trigger...;

and I want to substitue from my file ; by ;-- from the line where appears create trigger to the end of the file and keep intact the create table step and index in the file.


awk '/CREATE TRIGGER/,/END;/ { gsub(/;/, ";--") print} ' db2look.bk > toto

Regular expressions are case sensitive, and "/END/" is looking for the literal string "END".

Code:
awk '
   /create trigger/ { n = 1 }
   n                { gsub(/;/, ";--")
                      print }
 ' db2look.bk > toto

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, function of underscore char.

Hello Friends, I would appreciate so much if you could explain how the underscores works at the following code? Sorry if it sounds a bit novice question. awk -F',' 'NR==FNR{_=1;next}!_{print}' exclude infile KR, Eagle (6 Replies)
Discussion started by: EAGL€
6 Replies

2. Shell Programming and Scripting

awk substitution

Hi all, I need some help with substitution in awk. Is it possible to substitute field from awk output with string from file? For example: zcat /SMS/CDR/cdr_TC/callLogs*_*_2013092710*.gz | sed 's/:/;/g' | awk -F";" '{if($2==1 && $10~/389123456789/) print $36";"$37}' 2;19733248 I want... (6 Replies)
Discussion started by: vasil
6 Replies

3. Programming

AWK char '

Is it possibile to change char ' to another with awk? (2 Replies)
Discussion started by: MSMario
2 Replies

4. Shell Programming and Scripting

can I remove the first char using AWK?

Hi everyone, suppose that I have the following line: #test your knowledge can I use AWK to print the word "test" only? without the #? what should I change to this: awk '{print $1}' thanks in advance guys (2 Replies)
Discussion started by: Abdulelah
2 Replies

5. Shell Programming and Scripting

Substitution in AWK

I am trying to use AWK to replace dallinux02 to dallinux03 everywhere in the servers.txt file and move it over to "awk2". Here is my script "awk2.awk": gsub(/dallinux02/, "dallinux03"); print > "awk2" I am trying to run this using the following: $ awk -f awk2.awk... (3 Replies)
Discussion started by: ora_umair
3 Replies

6. Shell Programming and Scripting

help with awk substitution

Hi again. A have a CSV-file in the following format: 2008.09.01,15:17:42,9227096485,9233175320,CTC10,SMS,0901151742098314,Target_MSIS DN_is_blacklisted I want to have an awk command that will say: If the first 3 digits of $4 does not begin with 922 or 923, then make $8 say "Invalid... (3 Replies)
Discussion started by: daytripper1021
3 Replies

7. Shell Programming and Scripting

AWK substitution

I need to copy field 2 to field 3 for only those records that have the 1st field equal to account e.g. file account|123|789|xxx|yyy|zzz|... account_group|444|555|xxx|yy|zz|.... account|456|901|aaa|bbb|ccc|..... after running awk script should look like account|123|123|xxx|yyy|zzz|...... (4 Replies)
Discussion started by: klut
4 Replies

8. Shell Programming and Scripting

Convert Char to Dec using AWK

I'm facing a problem when trying to read a file and convert the content from char to decimal in ASCII. :confused: eg :- Input file : 20051231 8.00 experted result : 50484853495051493256464848 The content of input file is vary very day. I need to use AWK script to program it. Pls... (4 Replies)
Discussion started by: jasmine05
4 Replies

9. UNIX for Dummies Questions & Answers

awk variable substitution

for the command below, it looks for the 3rd field value matching "P" and printing it. awk '{if ($3 == "P") print}' file how would i express this if i use a loop to find more that 1 variable fro a list? this doesn't seem to work... cat list | while read n do awk '{if ($3 == "$n") print}'... (1 Reply)
Discussion started by: apalex
1 Replies

10. Shell Programming and Scripting

field substitution w/awk

I want to replace columns 15 thru 22 with a date in this format mmddyyyy in a file that has fixed record length of 110 columns. Only lines with column 1 = "T" will be changed but I can't seem to get it to work. I saw several postings and tried to work with them but they don't work for me... ... (12 Replies)
Discussion started by: giannicello
12 Replies
Login or Register to Ask a Question