Sponsored Content
Top Forums Shell Programming and Scripting Need shell script version of below perl code Post 302975219 by Corona688 on Thursday 9th of June 2016 01:10:47 PM
Old 06-09-2016
Another thing using my yanx library for shell xml.

Code:
$ cat test.xml

<?xml version="1.0"?>
<a q="r" z="w t f"><b><c><d>e</d>qwerqwe</c></b></a>


$ cat pretty.awk

BEGIN { ORS="\n" }
$1 ~ /[^ \r\n\t]/ {
        # Strip leading and trailing whitespace from cdata
        gsub(/[ \r\n\t]+$/,"",$2);
        gsub(/^[ \r\n\t]+/,"",$2);

        if(CTAG) {
                print "<" $1 ">";
                if($2) {
                        for(N=0; N<DEP; N++) printf("\t");
                        print $2;
                }
                for(N=1; N<DEP; N++) printf("\t");
        } else {
                print "";
                for(N=1; N<DEP; N++) printf("\t");
                printf("<%s>%s", $1, $2);
        }
}

$ awk -f yanx.awk -f pretty.awk test.xml

<?xml version="1.0"?>
<a q="r" z="w t f">
        <b>
                <c>
                        <d>e</d>
                        qwerqwe
                </c>
        </b>
</a>

$

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need Shell script for getting Firefox Browser Version

Hi, How to write a script for finding out firefox version in our linux machine? Could you please share the same? I am using Red Hat Linux machine. Thanks, Kammy (2 Replies)
Discussion started by: kjannu
2 Replies

2. Shell Programming and Scripting

How to run perl code within a shell script...?

Hi, I have a sheel script that invokes a perl script...Now, instead havin the perl script as a separate file I'd like put the contents in the sheel script itself...But I am not sure how ro run that perl script contents.please help me Thanks (1 Reply)
Discussion started by: vijay_0209
1 Replies

3. Shell Programming and Scripting

Perl Script Syntax error in version 4

Hi , I use the following simple perl script to find the yesterday time perl -e ' use POSIX(strftime); print POSIX::strftime("%a %b %e %H:%M:%S %Y", localtime(time-86400*$ARGV))' 1 However in the perl version 4 , it gives me the following error : Do the perl version 4 does not support... (4 Replies)
Discussion started by: youareapkman
4 Replies

4. Shell Programming and Scripting

convert perl code to shell script

This is about how to Monitoring folder for new files using shell script im doing a project using smsserver tools 3. i have used a perl script to handle incoming messages. the content of each message must be directed to a java program. this program generates the answer to reply to the user... (2 Replies)
Discussion started by: x34
2 Replies

5. Shell Programming and Scripting

Version Control Through the Shell Script

Version Control Through the Shell Script Hi Guys, Apologize for the big request, please take some time and read it completely... This is Very important for me, and ur help is Very much Appriciated. I want to maintain the Version control to all my scripts running in Production server, I am... (6 Replies)
Discussion started by: Anji
6 Replies

6. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

7. Shell Programming and Scripting

How to compare version values in shell script?

Hi, I need to compare two versions values and report only true or false depending on their difference result. like - echo $(echo "1.8 >= 2.0" | bc) 0 echo $(echo "2.0 >= 2.0" | bc) 1 but my task is to compare values like - echo $(echo "1.9.1 >= 2.0" | bc) (standard_in) 1: syntax... (3 Replies)
Discussion started by: abhitanshu
3 Replies

8. Shell Programming and Scripting

Portable Shell Script - Determine Which Version of Binary is Installed?

I currently have a shell script that utilizes the "Date" binary - this application is slightly different on OS X (BSD General Commmand) and Linux systems (gnu date). In particular, the version on OS X requires the following to get a date 14 days in the future "date -v+14d -u +%Y-%m-%d" where gnu... (1 Reply)
Discussion started by: colinjohnson
1 Replies

9. Shell Programming and Scripting

Shell Script for Java version switch

Hello all I am writing a shell script for unix, and I am trying to get it to ask me if instances are stopped, and then if the version of java running is correct, if not I want it to ask me to switch to the other bit version. I am newish to shell and not clear on how to to input prompts for yes/no... (3 Replies)
Discussion started by: bigbenn
3 Replies

10. Shell Programming and Scripting

How to capture the exit code of a shell script in a perl script.?

hi, i want to pop up an alert box using perl script. my requirement is. i am using a html page which calls a perl script. this perl script calls a shell script.. after the shell script ends its execution, i am using exit 0 to terminate the shell script successfully and exit 1 to terminate the... (3 Replies)
Discussion started by: Little
3 Replies
Perlanet::Trait::YAMLConfig(3pm)			User Contributed Perl Documentation			  Perlanet::Trait::YAMLConfig(3pm)

NAME
Perlanet::Trait::YAMLConfig - configure Perlanet through a YAML configuration file SYNOPSIS
package MyPerlanet; extends 'Perlanet'; with 'Perlanet::Traits::YAMLConfig'; my $perlanet = MyPerlanet->new_with_config( configfile => 'whatever.yml' ); $perlanet->run; DESCRIPTION
Allows you to move the configuration of Perlanet to an external YAML configuration file. Example Configuration File title: planet test description: A Test Planet url: http://planet.example.com/ author: name: Dave Cross email: dave@dave.org.uk entries: 20 opml: opml.xml page: file: index.html template: index.tt feed: file: atom.xml format: Atom cache_dir: /tmp/feeds feeds: - url: http://blog.dave.org.uk/atom.xml title: Dave's Blog web: http://blog.dave.org.uk/ - url: http://use.perl.org/~davorg/journal/rss title: Dave's use.perl Journal web: http://use.perl.org/~davorg/journal/ - url: http://www.oreillynet.com/pub/feed/31?au=2607 title: Dave on O'Reillynet web: http://www.oreillynet.com/pub/au/2607 METHODS
THIRTY_DAYS The default length of caching, if caching options are present in the configuration get_config_from_file Extracts the configuration from a YAML file AUTHOR
Oliver Charles, <oliver.g.charles@googlemail.com> COPYRIGHT AND LICENSE
Copyright (c) 2010 by Magnum Solutions Ltd. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2012-03-17 Perlanet::Trait::YAMLConfig(3pm)
All times are GMT -4. The time now is 06:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy