Need shell script version of below perl code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need shell script version of below perl code
# 8  
Old 06-09-2016
Try using the verbatim new line:
Code:
sed 's/>/>
/g'

# 9  
Old 06-09-2016
RudiC,the above command is not introducing line breaks,the same source file is created as replica as an output

Input:
Code:
<a><b>Bee</b><c>Sea</c><d><e>Eeeh!</e></d></a>

Below information may be useful
Desired output :
Code:
<?xml version="1.0"?>
<a>
  <b>Bee</b>
  <c>Sea</c>
  <d>
    <e>Eeeh!</e>
  </d>
</a>



Moderator's Comments:
Mod Comment What in "Please use code tags as required by forum rules!" don't you understand?

Last edited by RudiC; 06-09-2016 at 09:52 AM.. Reason: Added code tags.
# 10  
Old 06-09-2016
Code:
sed 's/>/>\n/g' file
<a>
<b>
Bee</b>
<c>
Sea</c>
<d>
<e>
Eeeh!</e>
</d>
</a>

# 11  
Old 06-09-2016
I agree with RudiC. The Perl script itself doesn't make sense in your case (so it doesn't make sense to "translate" it). For example, it reads the whole file into memory (which is not sensible with your file size), and even this, it does it inefficiently. Further, it introduces additional spaces into the file, making it even bigger.

So, forget the translation stuff, and just write your own tool, which splits the file at those places which suit you.
# 12  
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>

$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question