replace between tags


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers replace between tags
# 1  
Old 03-01-2011
replace between tags

Hello,

how can i do,

this:

Code:
<h1> linux </h1>

to

Code:
<h1> LINUX </h1>

it must be capitalized but how can i do that with SED???

thanks for help

Last edited by joeyg; 03-01-2011 at 11:43 AM.. Reason: Please use CodeTags around input/output & commands
# 2  
Old 03-01-2011
Perhaps you need to show a bigger example of your input data?
Code:
$ echo "<h1> linux </h1>"
<h1> linux </h1>

$ echo "<h1> linux </h1>" | sed "s/linux/Linux/"
<h1> Linux </h1>

This User Gave Thanks to joeyg For This Post:
# 3  
Old 03-01-2011
Why sed?

Code:
$> echo "<h1> linux </h1>"| awk '{$2=toupper($2); print}'
<h1> LINUX </h1>

This User Gave Thanks to zaxxon For This Post:
# 4  
Old 03-01-2011
Do you need all letters uppercase or just the first one? If you can settle for just the first one, this will work:
Code:
sed 's/<h1> \(.*\) <\/h1>/\u\1/'

This User Gave Thanks to glev2005 For This Post:
# 5  
Old 03-01-2011
May require GNU sed (if wanting to use \u switch)
This User Gave Thanks to ctsgnb For This Post:
# 6  
Old 03-02-2011
Quote:
Originally Posted by glev2005
Do you need all letters uppercase or just the first one? If you can settle for just the first one, this will work:
Code:
sed 's/<h1> \(.*\) <\/h1>/\u\1/'

Hello,

thanks for the help, but all letters must be uppercased.
# 7  
Old 03-02-2011
Quote:
Originally Posted by glev2005
Do you need all letters uppercase or just the first one? If you can settle for just the first one, this will work:
Code:
sed 's/<h1> \(.*\) <\/h1>/\u\1/'

So very nearly Smilie try the following:
Code:
echo '<h1> linux </h1>' | sed 's/\(<h1>\) *\([a-z]*\) \(<\/h1>\)/\1 \U\2\E \3/'

The \U uppercases the remaining text until it encounters a \L (lowercase remaining text) or \E end marker.
For more info on available modifiers in the substitution command in sed take a look at the info page for the s command in sed(way more informative than the man page).

Last edited by Skrynesaver; 03-02-2011 at 04:43 AM.. Reason: Added source for further learning
This User Gave Thanks to Skrynesaver 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

awk script to extract a column, replace one of the header and replace year(from ddmmyy to yyyy)

I have a csv which has lot of columns . I was looking for an awk script which would extract a column twice. for the first occurance the header and data needs to be intact but for the second occurance i want to replace the header name since it a duplicate and extract year value which is in ddmmyy... (10 Replies)
Discussion started by: Kunalcurious
10 Replies

2. Shell Programming and Scripting

Search and replace the string with new word using xml tags

Hi All i need to replace the url1 inside <remote> tag in below xml in first instance and in the second instance with url2. any help appreciated <locations> <hudson.scm.SubversionSCM_-ModuleLocation> <remote>https://svn2015.com/svn/repos/internalshard</remote> ... (4 Replies)
Discussion started by: madankumar.t@hp
4 Replies

3. Shell Programming and Scripting

Replace HTML tags using sed regex

I need all the end tags of </font> to be replaced with new line yet enclosing tag to be retained </font>. Please help me in this regard. Input: <font>abc</font>def<font>ghi</font> Output: <font>abc</font> def <font>ghi</font> (3 Replies)
Discussion started by: Badhrish
3 Replies

4. UNIX for Dummies Questions & Answers

How can I replace the lines that start with a star and replace it with numbers start from 1?

I need to replace the (*) in the fist of a list with numbers using sed for example > this file contain a list * linux * computers * labs * questions to >>>> this file contain a list 1. linux 2. computers 3. labs 4. questions (7 Replies)
Discussion started by: aalbazie
7 Replies

5. Shell Programming and Scripting

How can I replace data in between xml tags to required format?

Hi All, I have a requirement to change the data in xml file to required format. Below is the scenario. Please find the attached Xml file which contains data that I need to convert.. <ReleaseIndicatorList><ReleaseIndicator>Alternative... (0 Replies)
Discussion started by: Prathyu
0 Replies

6. Shell Programming and Scripting

Replace dashes positions 351-357 & 024-043 with 0 & replace " " if exis with 04 at position 381-382

I need to replace dashes (i.e. -) if present from positions 351-357 with zero (i.e. 0), I also need to replace dash (i.e “-“) if present between position 024-043 with zero (i.e. 0) & I replace " " (i.e. 2 space characters) if present at position 381-382 with "04". Total length of record is 413.... (11 Replies)
Discussion started by: lancesunny
11 Replies

7. Shell Programming and Scripting

Remove html tags with particular string inside the tags

Could someone, please provide a solution to the following: I would like to remove some tags from the "head" of multiple html documents across the web site. They look like <link rel="alternate" type="application/rss+xml" title="Business and Investment in the Philippines"... (2 Replies)
Discussion started by: georgi58
2 Replies

8. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

9. Shell Programming and Scripting

Replace multiple lines between tags using sed

I have a file example.txt with content look like this: <TAG> 1 2 3 </TAG> and I use a sed command to replace everything between <TAG></TAG> as below: sed -e 's/\(<TAG>\)*\(<.*\)/something/g' example.txt > example.txt.new But unfortunately, the command failed to replace as i want, it... (23 Replies)
Discussion started by: dollylamb
23 Replies

10. Shell Programming and Scripting

Replace space, that is not in html tags <> with new line using sed

Hi, I am working on transforming html code text into the .vert text format. I want to use linux utility sed. I have this regexp which should do the work: s/ \(?!*>\)/\n/g. I use it like this with sed: echo "you <we try> there" | sed 's/ \(?!*>\)/\n/g' ... The demanded output should be: you <we... (5 Replies)
Discussion started by: matt1311
5 Replies
Login or Register to Ask a Question