Sponsored Content
Top Forums Shell Programming and Scripting Insert tags which matches the pattern Post 302949713 by RavinderSingh13 on Wednesday 15th of July 2015 03:25:30 AM
Old 07-15-2015
Hello lxdorney,

Following is the explanation for same, hope that helps you. Also please always do show us your efforts as we all are here to learn. You can hit thanks button present at bottom of threads to anyone to whom you want to thank or appreciate.
Code:
awk '{if($0 ~ /^ \[A\.B/){gsub(/\[|\]/,X,$0);sub(/\,/,"<br>",$0)};print;next} 1'  Input_file
 
if($0 ~ /^ \[A\.B/)            #### looking for condition where it matches line which is starting from [A.B
gsub(/\[|\]/,X,$0)             #### If above if condition is TRUE then substitute all matches of [ and ] characters in that matched line with NULL.
;sub(/\,/,"<br>",$0)           #### Then substitute first match of charcter , wth <br>
;print                         #### Do print operation to newly formed line includng changes in above steps
next                           #### Now don't do any further operaion and go to next line
1                              #### awk works on condition and operation method so when condition is TRUE do certain operations as mentioned by user.
                                    so by giving 1 we are making condition TRUE and then no action/operatin given by me to it will perform default action/operation
                                    which is printing the lines.

Hope above helps you. Enjoy learning.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
tis_cond_signal(3)					     Library Functions Manual						tis_cond_signal(3)

NAME
tis_cond_signal - Wakes at least one thread that is waiting on the specified condition variable. LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <tis.h> int tis_cond_signal( pthread_cond_t *cond); STANDARDS
None PARAMETERS
Address of the condition variable (passed by reference) on which to signal. DESCRIPTION
When threads are present, this routine unblocks at least one thread that is waiting on the specified condition variable cond. When threads are not present, this routine has no effect. For more information about actions taken when threads are present, refer to the pthread_cond_signal(3) description. RETURN VALUES
If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows: Successful completion. The value specified by cond is not a valid condition variable. ERRORS
None RELATED INFORMATION
Functions: tis_cond_broadcast(3), tis_cond_destroy(3), tis_cond_init(3), tis_cond_wait(3) Manuals: Guide to DECthreads and Programmer's Guide delim off tis_cond_signal(3)
All times are GMT -4. The time now is 05:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy