Need to replace the date inside a node of several rdf files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to replace the date inside a node of several rdf files
# 1  
Old 11-05-2013
Need to replace the date inside a node of several rdf files

Hi,
I have a rdf zip file. This zip file consists of several *.rdf files.
I need to replace the date (this is different for each rdf) inside the node "Date_de_Publication_Periodique" of these rdf files.
e.g.,
Code:
 
awk '/Date_de_Publication_Periodique/ && /XMLSchema#date/' MM_NN-A1B1C1_ABC.rdf

gives:
Code:
 
 <j.1:Date_de_Publication_Periodique rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2013-10-30</j.1:Date_de_Publication_Periodique>

I need to replace this date: 2013-10-30 with my desired date.
With the shell script, I want to unzip the file, take out the strings (from the rdfs) for the mentioned node containing the date and replace it with my desired date (fixed date) for all the rdf files and then zip it back.
Following are my failed attempts:

Code:
awk '/Date_de_Publication_Periodique/ && /XMLSchema#date/' MM_NN-A1B1C1_ABC.rdf | awk '{gsub(/\d{4}\-\d{2}-\d{2}/,"JJJJJJ"); print}'

Code:
 
awk '/Date_de_Publication_Periodique/ && /XMLSchema#date/' MM_NN-A1B1C1_ABC.rdf | awk '{sub(/\d{4}\-\d{2}-\d{2}/,"JJJJJJ"); print }'

Need suggestions.
# 2  
Old 11-05-2013
Try:

Code:
awk '/Date_de_Publication_Periodique/ && /XMLSchema#date/ {sub(/[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}/,"JJJJJJ"); print} MM_NN-A1B1C1_ABC.rdf

# 3  
Old 11-06-2013
Quote:
Originally Posted by Chubler_XL
Try:

Code:
awk '/Date_de_Publication_Periodique/ && /XMLSchema#date/ {sub(/[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}/,"JJJJJJ"); print} MM_NN-A1B1C1_ABC.rdf


Thanks for the reply but your code is not working:

Code:
 
awk '/Date_de_Publication_Periodique/ && /XMLSchema#date/ {sub(/[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}/,"JJJJJJ"); print}' MM_NN-A1B1C1_ABC.rdf

Code:
 
        <j.1:Date_de_Publication_Periodique rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2013-10-30</j.1:Date_de_Publication_Periodique>

# 4  
Old 11-06-2013
Chubler_XL's solution works for me on AIX & Debian.

What's your OS? If you're running SunOS/Solaris then try with /usr/xpg4/bin/awk.
# 5  
Old 11-06-2013
I'm using linux and executing command in bash shell:

Quote:
bash-3.2$ uname -a
Linux SMP Mon Feb 21 05:52:39 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
# 6  
Old 11-06-2013
Try with sed:
Code:
sed '/Date_de_Publication_Periodique.*XMLSchema#date/s/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/JJJJJJ/' MM_NN-A1B1C1_ABC.rdf

This User Gave Thanks to Subbeh For This Post:
# 7  
Old 11-06-2013
Thank you subbeh and chubler_xl and carlom.
I figured out the working solution:
Quote:
awk '/Date_de_Publication_Periodique/ && /XMLSchema#date/' MM_NN-A1B1C1_ABC.rdf | sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/JJJJJJ/'
I forgot to add another requirement that I need to pick only the node with
"Date_de_Publication_Periodique" and "XMLSchema#date" and then replace the date inside with the desired date
While
Quote:
awk '/Date_de_Publication_Periodique/ && /XMLSchema#date/' MM_NN-A1B1C1_ABC.rdf
is returning that line but with sed
Quote:
sed '/Date_de_Publication_Periodique.*XMLSchema#date/s/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/JJJJJJ/' MM_NN-A1B1C1_ABC.rdf
it was returning multiple lines.

Last edited by Ribosome; 11-06-2013 at 08:35 AM.. Reason: corrected username
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. UNIX for Beginners Questions & Answers

Find all .sh files in file system and need to replace the string inside .sh files

Hi All, I need to write a script to find all "*.sh" files in /home file system and if any string find "*.sh" files with the name vijay@gmail.com need to replace with vijay.bhaskar@gmail.com. I just understood about the find the command to search .sh files. Please help me on this. find / -name... (3 Replies)
Discussion started by: bhas85
3 Replies

3. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

4. Shell Programming and Scripting

Extract Oracle sql queries from .fmb and .rdf files

Hi all, Thanks for your time! Regards, (1 Reply)
Discussion started by: a1_win
1 Replies

5. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

6. Shell Programming and Scripting

Searching for unknown date inside the file and replace to new date

Hello, Iam a newbies to Shell scripting. Iam trying to replace the date inside the file to new date. is there anyway that we can just use the pattern to search as "..." I have many files want to replace with the same date, and each file contains different date. Thanks for your help. ... (2 Replies)
Discussion started by: Daro
2 Replies

7. Shell Programming and Scripting

Find Node and replace line(s) preceding in xml file

Hello, I have an xml file whose contacts are like below: <Node>Apple <B>Value1</B> <B>Value2</B> <B>Value3</B> </Node> <Node>Mango <B>Value1</B> <B>Value2</B> <B>Value3</B> </Node> <Node>Apple <B>Value1</B> <B>Value2</B> <B>Value3</B> </Node> <Node>Bannana (3 Replies)
Discussion started by: umarsatti
3 Replies

8. Shell Programming and Scripting

ksh compare dates INSIDE a file (ie date A is > date B)

In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line. I thought I would... (4 Replies)
Discussion started by: right_coaster
4 Replies

9. Shell Programming and Scripting

compare date and time inside data of two files

i have two files with identical no of columns. 6th columns is date (MM/DD/YY format) and 7th columns is time (HH:MM:SS) format. I need to compare these two vaules and if the date & time is higher than fileA, save it on fileC; if the value is lower, then save it on fileD CONDITIONS... (7 Replies)
Discussion started by: ajiwww
7 Replies

10. Shell Programming and Scripting

how to read i-node informations (date of creation)

Hi, I'm looking for a way to get the date of creation for a file. Is it possible ? I know that these informations are in the i-node but I don't know how to access them (if the 'find' command can do it with option -ctime, I have reasons to believe in it). Thanks for helping me ! (1 Reply)
Discussion started by: mullmafr
1 Replies
Login or Register to Ask a Question