Wiki conversion with Awk or Sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wiki conversion with Awk or Sed
# 1  
Old 05-17-2010
Computer Wiki conversion with Awk or Sed

I have the words in twiki format that I want to convert to mediawiki format like below :

Code:
%BLUE%some words1%ENDCOLOR%

bla bla blab labdad sdadasd adsasdads oerdkfj kdfjs %PINK%some wordks2 123.4.5.6/26%ENDCOLOR%, ksdjak dkasjd kjfrjkfgjdkfgjdfkgjdgdfgdgf %PURPLE%1.2.3.4/28%ENDCOLOR%, dskd kjdfksjiertudfkjdk gjdkfgjdkgjdfkgjf:
<pre>
sdsa sdad asdlfkd %YELLOW%some workds3 %ENDCOLOR%255.255.255.240 %GREEN%someworkds4%ENDCOLOR%
</pre>

bla bla bla

The expected results should be like this :

Code:
<font color=blue>some words1</font>

bla bla blab labdad sdadasd adsasdads oerdkfj kdfjs <font color=pink>some wordks2 123.4.5.6/26</font>, ksdjak dkasjd kjfrjkfgjdkfgjdfkgjdgdfgdgf <font color=purple>1.2.3.4/28</font>, dskd kjdfksjiertudfkjdk gjdkfgjdkgjdfkgjf:
<pre>
sdsa sdad asdlfkd <font color=yellow>some workds3 </font>255.255.255.240 <font color=green>someworkds4</font>
</pre>

bla bla bla

I know sed or awk can do the job, but I have no idea...
This not a homework Smilie

TIA
# 2  
Old 05-17-2010
Code:
perl -pi.bak -e 's/%ENDCOLOR%/<\/font>/g; s/%(.*?)%/"<font color=\"".lc($1)."\">"/eg' *.twiki

# 3  
Old 05-17-2010
Another one with awk:
Code:
awk -F"%" '{
  for(i=2;i<NF;i+=2){
    if(i%4==0){
      $i="</font>"
    }
    else{
      $i="<font color=" tolower($i) ">"
    }
  }
}1' OFS="" file

# 4  
Old 05-17-2010
Thank you pludi / Franklin52.

Respect Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Base64 conversion in awk overlaps

hi, problem: output is not consistent as expected using external command in AWK description: I'm trying to convert $2 into a base64 string for later decoding, and for this when I use awk , I'm getting overlapped results , or say it results are not 100% correct. my code is: gawk... (9 Replies)
Discussion started by: busyboy
9 Replies

2. Shell Programming and Scripting

Numeral conversion in awk

I am running into conversion of string to numbers in awk that I can't understand and don't know how to deal with properly My script checks for numeric only field, I use this approach to do that: $1 + 0 == $1 It works most of the time, but in some cases it does not behave how I expect it to... (5 Replies)
Discussion started by: migurus
5 Replies

3. Shell Programming and Scripting

Decimal conversion number of the form x.xx to 0x.xx, sed?

Hello I have a file of the form ... num 0.12 num num num 25.53 num num num 7.82 num num ...... and I want to convert the 2nd field of each line adding a "0" at the numbers >= 0 and < 10 so the output will have the form: ... num 00.12 num num num 25.53 num num num 07.82 num... (10 Replies)
Discussion started by: phaethon
10 Replies

4. Shell Programming and Scripting

Conversion of line via awk or etc

Hello friends, could you help me about problem with my data lines. I suppose a simple awk code may help me. I have following data lines: (first line including 3 numbers and then a matrices of 4x10) 500 40 9 1 A B 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22... (6 Replies)
Discussion started by: rpf
6 Replies

5. Shell Programming and Scripting

Most vexing: Sed or Awk scripting for date conversion needed

Hi, I have some files being sent to me that have dates in them in this format: from 1/8/2011 15:14:20 and I need the dates in this format (mysql date format) To 2011-01-08 15:14:20 all I have so far is the regexp that detects the format: sed -r -e 's@\1/\2/\3\4\5\6]::$@do... (7 Replies)
Discussion started by: Astrocloud
7 Replies

6. Shell Programming and Scripting

awk string to number conversion

Can someone explain whats happening here: $ awk 'BEGIN {print (2.5 - 1)}' 1,5 2.5 - 1 is correctly calculated to 1,5 (using european locale) $ echo "2.5" | awk '{temp = $1 - 1; print temp}' 1 If i now pipe the string 2.5 through awk it seems at it truncates 2.5 to 2? What's the... (4 Replies)
Discussion started by: beow
4 Replies

7. Shell Programming and Scripting

File conversion and awk

Hi Everyone, I am confused with the output of the input file and I am using below command in script to get the expected output. Also I want to add another condition using logical AND (&&) in place of $2=="L"{$4=0-$4} as $2=="L" && $3=="L" {$4=0-$4} but I am getting some awk error. Can someone... (6 Replies)
Discussion started by: gehlnar
6 Replies

8. Shell Programming and Scripting

AWK Currency Conversion

How can I use awk command to convert values to currency. For example I have a database like follows John:200 smith:300 kim:405 and want it to out put like this John $200.00 (3 Replies)
Discussion started by: 3junior
3 Replies

9. Shell Programming and Scripting

awk script for date conversion

hi awk script for dd/mm/yyyy to yyyymmdd awk script for dd-mon-yyyy to yyyymmdd awk script for dd-mm-yyyy to yyyymmdd formate ..............urgent............. Thanks in advanced (2 Replies)
Discussion started by: charandevu
2 Replies

10. Shell Programming and Scripting

String Conversion in awk

I am porting a awk script from Windows to unix I_SALE_MEDIA=$67 if ((I_VOID_FLAG == "Y") && (I_SALE_MEDIA == 0)) NOW consider the case where I_SALE_MEDIA i.e $67 is "000" The above comparison works fine in Windows , but to make it work in Unix , I had to change the above as follows : ... (3 Replies)
Discussion started by: rohanrege
3 Replies
Login or Register to Ask a Question