Sponsored Content
Top Forums Shell Programming and Scripting Truncate the content within alt attribute to first 250 characters. Post 302286070 by joeyg on Tuesday 10th of February 2009 09:35:41 AM
Old 02-10-2009
Hammer & Screwdriver Another way to look at this

I duplicated some of the text inside that alt area so I could show it trimmed down. And then trimmed it at 150.
Note that it does not necessarily break nicely, and does not address the quotation " character.
However, this logic appears to trim on that field.

Code:
> cat file164
<image><img src="wstc_0007_0007_0_img0001.jpg" width="351" height="450" alt="This is the cover page. Brazil &#x2022; Japan &#x2022; Korea &#x2022; Mexico &#x2022; Singapore &#x2022; Spain" type="photograph" orient="portrait"/></image>
<image><img src="wstc_0007_0007_0_img0001.jpg" width="351" height="450" alt="This is the cover page. Brazil &#x2022; Japan &#x2022; Korea &#x2022; Mexico &#x2022; Singapore &#x2022; Spain Brazil &#x2022; Japan &#x2022; Korea &#x2022; Mexico &#x2022; Singapore &#x2022; Spain" type="photograph" orient="portrait"/></image>

> sed "s/alt/~alt/g" file164 | sed "s/type/~type/g" | awk -F"~" '{print $1,substr($2,1,150),$3}'
<image><img src="wstc_0007_0007_0_img0001.jpg" width="351" height="450"  alt="This is the cover page. Brazil &#x2022; Japan &#x2022; Korea &#x2022; Mexico &#x2022; Singapore &#x2022; Spain"  type="photograph" orient="portrait"/></image>
<image><img src="wstc_0007_0007_0_img0001.jpg" width="351" height="450"  alt="This is the cover page. Brazil &#x2022; Japan &#x2022; Korea &#x2022; Mexico &#x2022; Singapore &#x2022; Spain Brazil &#x2022; Japan &#x2022; Kor type="photograph" orient="portrait"/></image>

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

alt boot

ok guys, I have been given a big project, I need to implement alt boot on over 40+ servers, mainly solaris 8 and AIX 4.3, AIX 5.1. A couple of questions 1)can someone describe alt boot, my take is that if the primary disk fails(disk with root filesystems), this altboot disk takes over 2)can... (4 Replies)
Discussion started by: csaunders
4 Replies

2. UNIX for Dummies Questions & Answers

Truncate last <n> characters from a file

I am trying to concatenate 2 files, but before concatenation, I would like to strip off the final character from the first file. The final character is a form feed (ascii 012 / hex 0C) and there will be an unknown number of these characters in the file. It is only the very last one which I want... (1 Reply)
Discussion started by: Gwailo88
1 Replies

3. UNIX for Dummies Questions & Answers

Alt - Characters

in Win, one can use the Alt + 3-digit numeric code combination to spawn any ASCII character. Linux, OTOH has Ctrl-Shift-U + alphanumeric code combination to spawn any UNICODE character. bottom line: I'd like to be able to do what Win can do, please. I was told it was possible, but made... (5 Replies)
Discussion started by: ialoq
5 Replies

4. Shell Programming and Scripting

Truncate file name to 40 characters

Hello all. I would like to make a script (or two shell scripts) that will do the following. I need the maximum file name and directory name to be 38 characters long. As well, if shortening the file name ends up making all of the files in that directory have the same name, then I would like... (9 Replies)
Discussion started by: marcozd
9 Replies

5. Shell Programming and Scripting

how to delete special characters from the file content

Hello Team, Any one suggest how to delte the below special character from a file which is having one column 10 rows of same below content. ---------------------------------------- Kosten|bersicht gemd_ ' =Welche Kosten kvnnen... (2 Replies)
Discussion started by: kanakaraju
2 Replies

6. Shell Programming and Scripting

Truncate all characters and numbers in string - using perl

hi, I have an data from file where it has 20110904 234516 <<hdd-10#console|0c.57,passed,5,28,READ,0,20822392,8,5,4,0,40,0,-1,0,29909,25000,835,3.3,0,0,0,0,implied,0,0,2011/9/5-2:3:17,2011/9/5-2:3:47,X292_0F15,TAP ,NQ09,J40LTG\r\r\n I want to remove characters till #console| i.e want... (1 Reply)
Discussion started by: asak
1 Replies

7. Shell Programming and Scripting

Matching a pattern 250 characters up and down stream

hii all i have a file a which contains some thing like this strand smthg position + yyx 3020 - yyw 10,000 now i have another file (file2) which contains the data starting from 1 to n positions i want to refer first file if + ... (4 Replies)
Discussion started by: anurupa777
4 Replies

8. AIX

alt clone

I have two identical systems p740 with 2 lpars in each server. I dont want to install os from scratch on each lpar neither I want to use nim nor mksysb. Will it work perfectly if I install a fresh OS on 1 lpar and do alt disk clone for other lpras. My each lpar is having 2 physical disks. Now if... (2 Replies)
Discussion started by: vjm
2 Replies

9. Shell Programming and Scripting

How to truncate a string to x number characters?

Hello: I have a large file which contains lines like the following: 1/t123ab, &Xx:1:1234:12345:123456@ABCDEFG... at -$100.00% /t is a tab, spaces are as indicated the string "&Xx:1:1234:12345:123456$ABCDEFG..." has a slightly variable number of numbers and letters, but it always starts... (9 Replies)
Discussion started by: Tectona
9 Replies
DetectWS(3pm)						User Contributed Perl Documentation					     DetectWS(3pm)

NAME
XML::Filter::DetectWS - A PerlSAX filter that detects ignorable whitespace SYNOPSIS
use XML::Filter::DetectWS; my $detect = new XML::Filter::DetectWS (Handler => $handler, SkipIgnorableWS => 1); DESCRIPTION
This a PerlSAX filter that detects which character data contains ignorable whitespace and optionally filters it. Note that this is just a first stab at the implementation and it may change completely in the near future. Please provide feedback whether you like it or not, so I know whether I should change it. The XML spec defines ignorable whitespace as the character data found in elements that were defined in an <!ELEMENT> declaration with a model of 'EMPTY' or 'Children' (Children is the rule that does not contain '#PCDATA'.) In addition, XML::Filter::DetectWS allows the user to define other whitespace to be ignorable. The ignorable whitespace is passed to the PerlSAX Handler with the ignorable_whitespace handler, provided that the Handler implements this method. (Otherwise it is passed to the characters handler.) If the SkipIgnorableWS is set, the ignorable whitespace is simply discarded. XML::Filter::DetectWS also takes xml:space attributes into account. See below for details. CDATA sections are passed in the standard PerlSAX way (i.e. with surrounding start_cdata and end_cdata events), unless the Handler does not implement these methods. In that case, the CDATA section is simply passed to the characters method. Constructor Options o SkipIgnorableWS (Default: 0) When set, detected ignorable whitespace is discarded. o Handler The PerlSAX handler (or filter) that will receive the PerlSAX events from this filter. Current Implementation When determining which whitespace is ignorable, it first looks at the xml:space attribute of the parent element node (and its ancestors.) If the attribute value is "preserve", then it is *NOT* ignorable. (If someone took the trouble of adding xml:space="preserve", then that is the final answer...) If xml:space="default", then we look at the <!ELEMENT> definition of the parent element. If the model is 'EMPTY' or follows the 'Children' rule (i.e. does not contain '#PCDATA') then we know that the whitespace is ignorable. Otherwise we need input from the user somehow. The idea is that the API of DetectWS will be extended, so that you can specify/override e.g. which elements should behave as if xml:space="preserve" were set, and/or which elements should behave as if the <!ELEMENT> model was defined a certain way, etc. Please send feedback! The current implementation also detects whitespace after an element-start tag, whitespace before an element-end tag. It also detects whitespace before an element-start and after an element-end tag and before or after comments, processing instruction, cdata sections etc., but this needs to be reimplemented. In either case, the detected whitespace is split off into its own PerlSAX characters event and an extra property 'Loc' is added. It can have 4 possible values: o 1 (WS_START) - whitespace immediately after element-start tag o 2 (WS_END) - whitespace just before element-end tag o 3 (WS_ONLY) - both WS_START and WS_END, i.e. it's the only text found between the start and end tag and it's all whitespace o 0 (WS_INTER) - none of the above, probably before an element-start tag, after an element-end tag, or before or after a comment, PI, cdata section etc. Note that WS_INTER may not be that useful, so this may change. xml:space attribute The XML spec states that: A special attribute named xml:space may be attached to an element to signal an intention that in that element, white space should be preserved by applications. In valid documents, this attribute, like any other, must be declared if it is used. When declared, it must be given as an enumerated type whose only possible values are "default" and "preserve". For example: <!ATTLIST poem xml:space (default|preserve) 'preserve'> The value "default" signals that applications' default white-space processing modes are acceptable for this element; the value "preserve" indicates the intent that applications preserve all the white space. This declared intent is considered to apply to all elements within the content of the element where it is specified, unless overriden with another instance of the xml:space attribute. The root element of any document is considered to have signaled no intentions as regards application space handling, unless it provides a value for this attribute or the attribute is declared with a default value. [... end of excerpt ...] CAVEATS
This code is highly experimental! It has not been tested well and the API may change. The code that detects of blocks of whitespace at potential indent positions may need some work. AUTHOR
Enno Derksen is the Original Author. Send bug reports, hints, tips, suggestions to T.J. Mather at <tjmather@tjmather.com>. perl v5.10.0 2001-09-03 DetectWS(3pm)
All times are GMT -4. The time now is 10:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy