![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Truncate last <n> characters from a file | Gwailo88 | UNIX for Dummies Questions & Answers | 1 | 03-05-2008 12:52 AM |
| Dynamic Attribute Changes | er_aparna | Shell Programming and Scripting | 8 | 10-31-2006 12:57 AM |
| UNIX->C++ File attribute | mizrachi | High Level Programming | 0 | 08-05-2004 08:34 AM |
| File attribute Help please | Cube3k | Linux | 1 | 12-15-2003 05:31 PM |
| File Created On attribute | dpalmer | UNIX for Dummies Questions & Answers | 1 | 09-16-2001 11:44 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Truncate the content within alt attribute to first 250 characters.
I have a xml file which contains image tag as follows:
<image><img src="wstc_0007_0007_0_img0001.jpg" width="351" height="450" alt="This is the cover page. Brazil • Japan • Korea • Mexico • Singapore • Spain" type="photograph" orient="portrait"/></image> Now, i want to write a script that will count whether the number of characters within alt attribute are greater than 250 and if it is; the data within alt attribute should be truncated to contain only first 250 characters. It would be really nice if anybody could provide me the way to do so. |
|
|||||
|
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 • Japan • Korea • Mexico • Singapore • 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 • Japan • Korea • Mexico • Singapore • Spain Brazil • Japan • Korea • Mexico • Singapore • 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 • Japan • Korea • Mexico • Singapore • 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 • Japan • Korea • Mexico • Singapore • Spain Brazil • Japan • Kor type="photograph" orient="portrait"/></image>
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|