Script or SED command for [[Xxxx Xxxx Xxxx]] to [[Xxxx xxx xx]]


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script or SED command for [[Xxxx Xxxx Xxxx]] to [[Xxxx xxx xx]]
# 1  
Old 11-22-2009
Script or SED command for [[Xxxx Xxxx Xxxx]] to [[Xxxx xxx xx]]

Hi,

To comply with a new naming convention on a mediawiki site we have to run a SED or other PERL command to change all instances of

[[Xxxxx xxx Xxxxx]] or [[Xxxxx Xxxx]] or [[Xxxxx Xxxxxx Xxxxx]]

to

[[Xxxxx xxxxx xxxx]]

Can someone please explain how to do this...

It has to be done on a mysql dump, so if there is a way to do this in mysql even better, otherwise I will make a dump of the database and run it then and restore the database.

Thank you.

---------- Post updated 22-11-09 at 05:05 AM ---------- Previous update was 21-11-09 at 06:59 PM ----------

Pleaseeeeeeeeeeeeeeee
# 2  
Old 11-23-2009
Assuming [[Xxxxx xxx Xxxxx]] or [[Xxxxx Xxxx]] or [[Xxxxx Xxxxxx Xxxxx]]
means letters A-Za-z I do not see how this can be done without a lot more information

For example:
[[Xxxxx xxx Xxxxx]] becomes [[Xxxxx xxxxx xxxx]]. The middle term gained characters xxx to become xxxxx. Where do the extra characters come from? The last term lost one character Xxxxx to become xxxx. Do we drop the X?
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 11-25-2009
your OR examples aren't the same length. The new string is len 14, x's only, and the original 13, 9 and 16 . So you need to define rules of how to handle over and under size as most databases don't necessarily handle overs well.

in sql you could do it but it would be messy but look up the equivalent of charindex, Sybase, in mysql and strip the spaces then substring the result out into the new format applying whatever rules you decide for overs and unders.

I'm assuming the [ is for display purposes? If not then it's not an issue just ignore them.

dump to file, assuming a one field file.
awk -F" " '{print tolower($1$2$3)}' tmp.tmp > tmp.tmp1 #strips spaces
awk '{print toupper(substr($0,1,1)) substr($0,2,4) " " substr($0,5,5) " " substr($0,11,5)}' tmp.tmp1 > newfile.tmp

if you read up on BEGIN and END you can string it all in one awk statement. However theres more work needed to handle the unders and overs.

You could do it like this awk -F " " '{print tolower($1$2$3)}' tmp.tmp | awk '{print toupper(substr($0,1,1)) substr($0,2,4) " " substr($0,5,5) " " substr($0,11,5)}' > newfile.txt but I usually prefer to do each command on a separate line so when I'm trying to work out what's not working at 2am I don't have to parse the piping of commands.

Last edited by StevePr; 11-25-2009 at 09:34 AM..
This User Gave Thanks to StevePr For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command + replace the extension (.xxx) by *

Hello, I'm on HP Unix and in a Job, I tried to extract all files from a folder, and replace the extension (.xxxx) by '*' , remove duplicates and move the result in a file.. Example : Folder has : ABC, CCC.txt, CCC.sf, CCC.sfd, DDD I need to generate and output file with : ... (6 Replies)
Discussion started by: royinfo.alain
6 Replies

2. UNIX for Dummies Questions & Answers

Grep file and print value only if the following line doesnt contain value xxxx

Hi All, I have some large files which I would like to obtain some data from, I want to grep (or alturnative method) out certain values hut only if the folowing line doesnt contain a certain value. I will explain better below showing an example print of the data. NE : V0001 NE : V0002... (6 Replies)
Discussion started by: mutley2202
6 Replies

3. Shell Programming and Scripting

Printing paragraph between semicolons having XXXX

Hello experts, I have below file: 1 2 3 4 5 6 ; 7 8 9 10 XXXX 1 ; 2 3 (4 Replies)
Discussion started by: manuswami
4 Replies

4. Red Hat

Gnome3 locksup on new Linux kernel 12.6.xxx & 12.5.xxx

Hi Forum Ive been having a problem with the kernal(s) for some strange reason it every time I try and access the date and time/calendar or system settings it locks up the whole laptop and nothing responds. :(. This doesn't happen 11.10.xxx kernel . Any help would be much appreciated and thank you... (1 Reply)
Discussion started by: ShinTec
1 Replies

5. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

6. Shell Programming and Scripting

Script for delete tmp files older than 15 days and owned by "xxx" id

Hi All , I want to delete files from /tmp directory created by "xxxx" id. because i got the list says more than 60 thousand files were created by "xxxx" id since 2002. The /tmp directory has lot of files created by different user ids like root,system etc.. But, i need a script to... (2 Replies)
Discussion started by: vparunkumar
2 Replies

7. Solaris

sar : insufficient address space to load xxxx device records

Hello, i am using Solaris 10, The sar running in my system might be corrupted, but not sure why as there has been no updates to it ( to the best of my knowledge) and it was working fine until few days back. If i try to get sar reports using sar -o <filename> 60 180 there is no error but the... (2 Replies)
Discussion started by: nimi20
2 Replies

8. UNIX for Dummies Questions & Answers

Removing spaces between XML tags<XX XX> -> <XXXX>

hey guys, i have an XML like this: <documents> <document> <Object ID>100114699999</Object ID> <Object Create Date Time>2008-04-07T00:00:00</Object Create Date Time> </document> <documents> I need all my tags within the XML to not include any spaces. i.e. everything between <t a g> in... (8 Replies)
Discussion started by: sharoff
8 Replies

9. Shell Programming and Scripting

First Script: Query every table with column xxx.

Hi all, Im new to scripting and have no idea how to start this. Recently I had to Query an Oracle database to find a count(distinct version) from every single table inside. I want to write this up into a script for the future. I have a template to connect to the database, so that is not the... (1 Reply)
Discussion started by: Iniquity
1 Replies

10. UNIX for Dummies Questions & Answers

rm: Unable to remove directory xxxx/xxxx: File exists

Hi Everyone, I am having problem to delete an "empty" folder ( messages attached ). It displays "total 12" when i typed "ls -lart" on the fnxroot44 folder, but i can't view any file. Is there any way to view those unseen files ? I don't know why option "a" is not working this time. Would... (1 Reply)
Discussion started by: deejay
1 Replies
Login or Register to Ask a Question