Find required files by pattern in xml files and the change the pattern on Linux

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
Question Find required files by pattern in xml files and the change the pattern on Linux


I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found.

For instance.

I can start the script with arguments for keyword and for value, i.e keyword "another word"

Script should find all files with keyword and do the following changes in the files containing keyword.

<keyword></keyword> should be the same <keyword></keyword>
<keyword>some word</keyword> should be like this <keyword>some word, another word</keyword>

In other words if initially value in keyword node was empty, then I don't need to change it and if it contains some value then I need to extend it with the value I will specify.

What is best way to do this on Linux?

Thank you.
# 2  
Listing is easy enough, I guess:
grep -l '<keyword>[^<]*some word[^<]*<\/keyword>' *.xml

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #683
Difficulty: Medium
According to both NetMarketShare and WikiMedia, Safari has a desktop market share of over 6% in 2019.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

2. Shell Programming and Scripting

Script to find only files that contain pattern

Actually I googled it and found != *Frequent* works! So now I have zero questions Thanks for reading, anyway! Actually I got this working see below. I just now have one question: How do you use a test condition (such as with Frequent) that takes whitespace into account for example, if the... (2 Replies)
Discussion started by: newbie2010
2 Replies

3. Shell Programming and Scripting

split XML file into multiple files based on pattern

Hello, I am using awk to split a file into multiple files using command: nawk '{ if ( $1 == "<process" ) { n=split($2, arr, "\""); file=arr } print > file }' processes.xml <process name="Process1.process"> ... (3 Replies)
Discussion started by: chiru_h
3 Replies

4. Shell Programming and Scripting

How to find files in a pattern directory?

Hi, I have more than 1000 directories under one directory (lets says under /home/). Sub directories are like A1 to A100,B1 to B100 etc.. Here my problem is I need to find the files older than 10 days in the directories which starts with A*. I tried some thing like this which is not... (2 Replies)
Discussion started by: shhrikanth
2 Replies

5. Shell Programming and Scripting

Help required to find pattern

Hi All, I have a oracle code & want to exclude the comments present in the code. Below may be the pattern can be considered for eg. -- ALTER TABLE ALTER TABLE -- To create In above sample, First line is full commented line as it starts with "--" Wheras the second line is starting... (2 Replies)
Discussion started by: gr8_usk
2 Replies

6. Shell Programming and Scripting

To find the files with pattern and display

Hi all, Im looking for a script(bash,perl) to find the files which has content with ORA (Mostly will be from log file)if we find those content,need to send a mail alert to the team members with the files which are matched. This script should run daily so that it should search for the files... (1 Reply)
Discussion started by: preetha_83
1 Replies

7. UNIX for Dummies Questions & Answers

find files NOT matching name pattern

Hi, I have following files in my directory: /TESTDONTDEL> ls -alt total 14 drwxr-xr-x 2 oracle dba 1024 May 15 06:30 . -rw-r--r-- 1 oracle dba 40 May 15 06:30 exception.txt -rw-r--r-- 1 oracle dba 19 May 15 06:22 ful_1234_test1.txt -rw-r--r-- 1... (2 Replies)
Discussion started by: sagarparadkar
2 Replies

8. UNIX for Dummies Questions & Answers

Find files matching a pattern

Hi, I am writing a BASH shell script. I would like to count all the files in the CURRENT directory matching a specific pattern. Could someone suggest the best/simplest way to do this. I have thought of these solutions (for simplicity the pattern is all files starting with A): ls -1 *A | wc -l... (5 Replies)
Discussion started by: msb65
5 Replies

9. Shell Programming and Scripting

How to find files which has more than one occurance of pattern

Hello Everyone, Please help me in finding out the solution. The problem is .. lets say i have 600 files in a directory. All 600 files are shell script files. Now i need to find out the files which contains a pattern "SHELL" more than once. No matter how the pattern occurs , it can be in... (10 Replies)
Discussion started by: Prahlad
10 Replies

10. UNIX for Dummies Questions & Answers

find pattern in FILES and replace it ??

Hi How can I looking for a pattern found in more than one file and replace it with anther pattern this what I was used: find . -name "account.adrs" -depth -follow -exec grep -l "Email = ;" {} \; this print the files name -which is account.adrs- and its path -which is deferent for each... (4 Replies)
Discussion started by: tamer
4 Replies

Featured Tech Videos