Insert tags which matches the pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert tags which matches the pattern
# 8  
Old 07-15-2015
Is this only print the output to the screen how about if write to another file with desame filename but on other directory:
something like this:
Code:
awk '(/^ \[A.B/ && sub(/,/,"<br>") && gsub(/[\[\]]/,""))+1' file >/tmp/file
awk '(/^ \[A.B/ && sub(/,/,"<br>") && gsub(/[\[\]]/,""))+1' file1 >/tmp/file1

Here I have done now
Code:
find /root/dir/ -name *.* | awk '{print "awk '\'\/\<div" "id\=\\\\\\'"""left\'\\'\'\"""\/{a\=1}\/\<\\\\\\\!""""--" "footer" "template" "--\>\/{print\;a\=0}a\'' "$1}'

Ouput:
Code:
awk '/<div id=\"left\"/{a=1}/<\!-- footer template -->/{print;a=0}a' /root/dir/2000/file1.htm
awk '/<div id=\"left\"/{a=1}/<\!-- footer template -->/{print;a=0}a' /root/dir/2000/file2.htm

I want to achieve something like this:
Code:
awk '/<div id=\"left\"/{a=1}/<\!-- footer template -->/{print;a=0}a' /root/dir/2000/file1.htm >/root/dir1/2000/file1.htm
awk '/<div id=\"left\"/{a=1}/<\!-- footer template -->/{print;a=0}a' /root/dir/2000/file2.htm >/root/dir1/2000/file2.htm


Last edited by lxdorney; 07-15-2015 at 11:34 PM..
# 9  
Old 07-16-2015
Code:
awk '{print "awk '\'\/\<div" "id\=\\\\\\'"""left\'\\'\'\"""\/{a\=1}\/\<\\\\\\\!""""--" "footer" "template" "--\>\/{print\;a\=0}a\'' "$1}'

You know, the reason for using all those ungodly escapes is the shell. If you make an awk script file and then, call it as awk -f filename it would eliminate quite a bit of clutter.

However, I have the impression that what you're doing is the equivalent of taking an automatic M16 rifle, bend it with a slight curve, along its body, attach a string to the barrel and to the stock and try to shoot arrows with it.

Nevertheless, without a clearer explanation of what's the end result, that's what you got.
# 10  
Old 07-16-2015
Yes you right, Im trying to find way locate all html files and cut the content between two patterns to clean. and write to another location
# 11  
Old 07-16-2015
Quote:
Originally Posted by Don Cragun
Although the above works with some versions of awk, the standards say the only backslash escapes that are required to be recognized by awk are:\\, \/, \", \a, \b, \f, \n, \r, \t, and \v, and \d, \dd, and \ddd (where d is an octal digit). Anything else following a \ in a bracket expression produces undefined behavior.

In a bracket expression, if the first character inside the brackets (or immediately after the ^ in a non-matching list in a non-matching bracket expression) is a closing bracket, that closing bracket is a character in the list; not a terminator for the matching expression. And, inside a bracket expression, there is nothing special about an opening bracket except when it appears as the start of a collating symbol expression, the start of an equivalence class expression, or the start of a character class expression. So, two standard ways to specify an ERE containing a bracket expression matching the two characters [ and ] in awk are /[][]/ and "[][]".

Thank you so much Don I got something new to learn from you Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract the whole set if a pattern matches

Hi, I have to extract the whole set if a pattern matches.i have a file called input.txt input.txt ------------ CREATE TABLE ABC ( A, B, C ); CREATE TABLE XYZ ( X, Y, Z, P, Q ); (6 Replies)
Discussion started by: raju2016
6 Replies

2. Shell Programming and Scripting

awk with range but matches pattern

To match range, the command is: awk '/BEGIN/,/END/' but what I want is the range is printed only if there is additional pattern that matches in the range itself? maybe like this: awk '/BEGIN/,/END/ if only in that range there is /pattern/' Thanks (8 Replies)
Discussion started by: zorrox
8 Replies

3. Shell Programming and Scripting

Insert certain field of matched pattern line above pattern

Hello every, I am stuck in a problem. I have file like this. I want to add the fifth field of the match pattern line above the lines starting with "# @D". The delimiter is "|" eg > # @D0.00016870300|0.05501020000|12876|12934|3||Qp||Pleistocene||"3 Qp Pleistocene"|Q # @P... (5 Replies)
Discussion started by: jyu3
5 Replies

4. Shell Programming and Scripting

Insert new pattern in newline after the nth occurrence of a line pattern - Bash in Ubuntu 12.04

Hi, I am getting crazy after days on looking at it: Bash in Ubuntu 12.04.1 I want to do this: pattern="system /path1/file1 file1" new_pattern=" data /path2/file2 file2" file to edit: data.db - I need to search in the file data.db for the nth occurrence of pattern - pattern must... (14 Replies)
Discussion started by: Phil3759
14 Replies

5. Shell Programming and Scripting

How Not to Delete Words that matches a PATTERN

Hi, I have a test file name test.txt with its contents string 21345 qwee strinn strriin striin i need to delete all the words except the word STRING I used the command cat test.txt | sed 's/^..*$/**/g' but the output entries still contain strinn strriin striin. Plz Help me out.... (5 Replies)
Discussion started by: Ananth12
5 Replies

6. Shell Programming and Scripting

Remove if the above line matches pattern

but keep if does not I have a file: --> my.out foo: bar foo: moo blarg i am on vacation foo: goose foo: lucy foo: moose foo: stucky groover@monkey.org foo: bozo grimace@gonzo.net dear sir - blargo blargo foo: goon foo: sloppy foo: saudi gimme gimme gimme (3 Replies)
Discussion started by: spacegoose
3 Replies

7. Shell Programming and Scripting

get value that matches file name pattern

Hi I have files with names that contain the date in several formats as, YYYYMMDD, DD-MM-YY,DD.MM.YY or similar combinations. I know if a file fits in one pattern or other, but i donīt know how to extract the substring contained in the file that matches the pattern. For example, i know that ... (1 Reply)
Discussion started by: pjrm
1 Replies

8. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

9. Shell Programming and Scripting

awk to count pattern matches

i have an awk statement which i am using to count the number of occurences of the number ,5, in the file: awk '/,5,/ {count++}' TRY.txt | awk 'END { printf(" Total parts: %d",count)}' i know there is a total of 10 matches..what is wrong here? thanks (16 Replies)
Discussion started by: npatwardhan
16 Replies

10. Shell Programming and Scripting

Extract if pattern matches

Hi All, I have an input below. I tried to use the awk below but it seems that it ;s not working. Can anybody help ? My concept here is to find the 2nd field of the last occurrence of such pattern " ** XXX ccc ccc cc cc ccc 2007 " . In this case, the 2nd field is " XXX ". With this "XXX" term... (20 Replies)
Discussion started by: Raynon
20 Replies
Login or Register to Ask a Question