is there a way to add a td tag with sed?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting is there a way to add a td tag with sed?
# 1  
Old 10-05-2010
is there a way to add a td tag with sed?

example code

What I want to do is add an ending TD tag ( </td> )

Code:
sed 's/./&</td>/g'


Simple data:

<tr><td>listenhere<insert/tdtaghere><tr><td>listenhere<insert/tdtaghere><tr><td>listenhere<insert/tdtaghere>

Last edited by puttster; 10-05-2010 at 04:46 PM..
# 2  
Old 10-05-2010
Ending where? The end of a line? The end of a paragraph?

Please provide sample data as well.
# 3  
Old 10-05-2010
Suppose you had a CSV file you wanted to be a table. Ignoring quotes and quoted commas for the moment (Access 2000 does, so why not me?), this would turn it into table guts:

Code:
sed '
  s/[^,]*/<TD>&<\/TD>/g
  s/,//g
  s/.*/<TR>&<\/TR>/
 '

Take every area of not comma and wrap it in td, dump the commas and wrap each line in tr.
This User Gave Thanks to DGPickett For This Post:
# 4  
Old 10-05-2010
What about if I wanted to sed out every character except for the first character of a word?

OR

Take what you sed out and attach it to a variable so that you can call upon it later?

Code:
$parameter

sed s/^$parameter/./g


Last edited by puttster; 10-05-2010 at 05:26 PM..
# 5  
Old 10-06-2010
What about if I wanted to sed out every character except for the first character of a word?

Code:
 
  This works with 'old' regex (someone changed the meaning or \< and \> on us) and words of only letters:
 
    s/\<\([a-zA-Z]\)[a-zA-Z]*/\1/



Take what you sed out and attach it to a variable so that you can call upon it later?

Code:
 
  Env variables can hold a lot, often up to a meg total:
 
   export hold_table_guts=$( sed_script )

Did you say what language you were writing the web page in? I use ksh, but on my own server! PERL is traditional, and then came ASP, JSP and all the flood!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find files in sub dir with tag & add "." at the beginning [tag -f "Note" . | xargs -0 {} mv {} .{}]

I am trying find files in sub dir with certain tags using tag command, and add the period to the beginning. I can't use chflags hidden {} cause it doesn't add period to the beginning of the string for web purpose. So far with my knowledge, I only know mdfind or tag can be used to search files with... (6 Replies)
Discussion started by: Nexeu
6 Replies

2. Shell Programming and Scripting

awk to extract tag and add to each line

In the awk below which executes as is, I am trying to add a condition that will extract the text or value after the FR= for the lines in each line of file1 compared to file2. As is the lines between the two files are either a match, Missing in file 1, or Missing in file2, but I can not add the... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

sed search and replace after xml tag

Hi All, I'm new to sed. In following XML file <interface type='direct'> <mac address='52:54:00:86:ce:f6'/> <source dev='eno1' mode='bridge'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> ... (8 Replies)
Discussion started by: varunrapelly
8 Replies

4. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

5. Shell Programming and Scripting

sed substition within XML tag

Hi all, I basically want to remove certain characters from within a certain XML tag: From: <mytagone>hello 1-2-3 world</mytagone> <mytagtwo>hello 1-2-3 world</mytagtwo> To: <mytagone>hello 1 2 3 world</mytagone> <mytagtwo>hello 1-2-3 world</mytagtwo> Is this possible using sed... (6 Replies)
Discussion started by: Jedimark
6 Replies

6. Shell Programming and Scripting

How can i find texts inside a html tag using sed?

How can i find texts inside a html tag using sed? Html texts: What i tried: cat infile | sed -e 's/\(<kbd*\)\(.*\)\(kbd>\)/\2/ Expected result like this: sed -i -e 's/@colophon/@@colophon/' \ -e 's/doc@cygnus.com/doc@@cygnus.com/' bfd/doc/bfd.texinfo (5 Replies)
Discussion started by: cola
5 Replies

7. Shell Programming and Scripting

Search for a html tag and print the entire tag

I want to print from <fruits> to </fruits> tag which have <fruit> as mango. Also i want both <fruits> and </fruits> in output. Please help eg. <fruits> <fruit id="111">mango<fruit> . another 20 lines . </fruits> (3 Replies)
Discussion started by: Ashik409
3 Replies

8. Shell Programming and Scripting

Add the html tag first and last line the file

Hi, i have 30 html files and i want to add the html tag first (<html>) and end of the line </html> tag..How to do it in script. Thanks, (7 Replies)
Discussion started by: bmk
7 Replies

9. Shell Programming and Scripting

sed, awk [TAG]$content[/TAG] How to get var in $content in textfile?

Hello, I got a Qstion. Im posting to a phpbb forum with bash and curl.. i have a text file with the following tags that i post to the forum: $var1 $var2 $var3 How can i with sed or awk put var content from shell script between the ... in the... (7 Replies)
Discussion started by: atmosroll
7 Replies

10. Shell Programming and Scripting

Sed command to clean xml tag

Hi, Can someone help me come up with a generic sed command to clean a tag off its attributes? For eg. Input String - <tag attrib=new>This String</tag> should undergo a sed transformation to get Output String - <tag >This String</tag> This works - echo "<tag attrib=new>This</tag>" |... (3 Replies)
Discussion started by: iamwha1am
3 Replies
Login or Register to Ask a Question