Visit Our UNIX and Linux User Community


How to apply a "tolower" AWK to a few parts of a document


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to apply a "tolower" AWK to a few parts of a document
# 1  
Old 05-05-2009
How to apply a "tolower" AWK to a few parts of a document

Hi people,
i have a nice problem to solve..
in an text page i must change all the "*.php" occourences to the respective lowercase..

Example:

...
<tr><td>
<form action="outputEstrazione.php" method="get">
<table cellspacing='0,5' bgcolor='#000000'><tr><td>
<font size='2' color='#ffffff' face='tahoma'><b>Lettura documento input</b></font></td></tr><tr><td>
<table width='100%' height='100%' bgcolor='#ffffff' cellpadding='1'><tr><td>
...

must be modified in:

...
<tr><td>
<form action="outputestrazione.php" method="get">
<table cellspacing='0,5' bgcolor='#000000'><tr><td>
<font size='2' color='#ffffff' face='tahoma'><b>Lettura documento input</b></font></td></tr><tr><td>
<table width='100%' height='100%' bgcolor='#ffffff' cellpadding='1'><tr><td>
...




("outputEstrazione.php" >>> "outputestrazione.php")
Can you help me? It seems so simply but it's not for me Smilie
tnx! Smilie
# 2  
Old 05-05-2009
you are using any webserver and want to convert it on runtime? or you just have a text file?

In general,
for a text file, you can use

Quote:
cat filename | tr '[:upper:]' '[:lower:]'
if you must want to use awk..

Quote:
awk '{ print tolower($0)}' infile
# 3  
Old 05-05-2009
you can use sed to do that also:

Code:
sed  '/\.php/{
h
s/<.*\"\(.*\.php\)\".*>$/\1/
y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyj/
G
s/\(.*\)\n\(<*[^"]*\"\).*\.php\(\".*>\)/\2\1\3/
}' filename

cheers,
Devaraj Takhellambam
# 4  
Old 05-05-2009
Or you could use perl:

Code:
$
$ cat input.txt
<tr><td>
<form action="outputEstrazione.php" method="get">
<table cellspacing='0,5' bgcolor='#000000'><tr><td>
<font size='2' color='#ffffff' face='tahoma'><b>Lettura documento input</b></font></td></tr><tr><td>
<table width='100%' height='100%' bgcolor='#ffffff' cellpadding='1'><tr><td>
$
$
$ perl -ne '{if (/(^.*?")(.*?)(\.php.*$)/) {print $1.lc$2.$3,"\n"} else {print}}' input.txt
<tr><td>
<form action="outputestrazione.php" method="get">
<table cellspacing='0,5' bgcolor='#000000'><tr><td>
<font size='2' color='#ffffff' face='tahoma'><b>Lettura documento input</b></font></td></tr><tr><td>
<table width='100%' height='100%' bgcolor='#ffffff' cellpadding='1'><tr><td>
$
$

HTH,
tyler_durden

________________________________________________________
"If you don't claim your humanity, you will become a statistic."
# 5  
Old 05-06-2009
how about below perl code?

Code:
open $fh,"<","yourfile";
while(<$fh>){
	s/\b(.*)\.php/lc $1 . '.php'/e;
	print;
}

# 6  
Old 05-06-2009
hey great great thanks!!
Great solutions, i've chosen the perl one and it works perfectly:
perl -ne '{if (/(^.*?")(.*?)(\.php.*$)/) {print $1.lc$2.$3,"\n"} else {print}}' input.txt

I've never used perl, but i often see it's very useful and want to learn it, do you have any link to a good tutorial (not too complex, for a beginner)?

Thanks again for all the replies! You are simply the best UNIX forum on the net Smilie

p.s. sorry for my bad english ^^

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting Parts of String "#" vs "%"

Hello, I have a question regarding extracting parts of a string and the meaning of # and % in the syntax. I created an example below. # filename=/first/second/third/fourth # # echo $filename /first/second/third/fourth # # echo "${filename##*/}" fourth # # echo "${filename%/*}"... (3 Replies)
Discussion started by: shah9250
3 Replies

2. Shell Programming and Scripting

Converting parts of a string to "Hex"

Hi Guys, writing a small shell script, i need to convert parts of a string to "Hex". The problem is that it is not the full string that needs to be converted. I think it's best to show an example: $astring = "xxxxxx ABC+10+##########+DEF xxxx" This is only an example to show how the... (9 Replies)
Discussion started by: HansHansen
9 Replies

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

read parts of binary files by "ranges"

i read the "cat" manpages, but i could not find to tell it like "read file XY.BIN from byte 1000 to byte 5000" can somebody please point me into the right direction? cat would be the ideal tool for my purpose, the way it behaves, but i miss this ranges option. thanks for any input. (2 Replies)
Discussion started by: scarfake
2 Replies

6. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

7. Shell Programming and Scripting

help for saving vertical datas to horizontal with "awk" or "cut"

hi, i have a file having datas like that ./a.txt 12344 12345 12346 12347 ..... ..... ... i want to save this datas to another file like that ./b.txt 12344 12345 12346 12347 ... ... ... i think awk can make this but how? :) waiting for ur help. (3 Replies)
Discussion started by: mercury
3 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Programming

Splitting the console into 2 "parts"

Good morning, I would like to make a little interface for an application which will split the console in 2 "parts": 1 top area to print messages & 1 command prompt. The printed messages are asynchronous to the command prompt, what I mean is that while while the user types a command a... (2 Replies)
Discussion started by: jonas.gabriel
2 Replies

Featured Tech Videos