Insert a function in a jsp file using Shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert a function in a jsp file using Shell scripting
# 1  
Old 06-08-2009
Insert a function in a jsp file using Shell scripting

Greetings to all.I am new to the forum as well as to UNIX as well.I have a jsp file which has the following

selectedStartMonth = request.getParameter( "startMonth" );
selectedStartDay = request.getParameter( "startDay" );
selectedStartYear = request.getParameter( "startYear" );
selectedEndMonth = request.getParameter( "endMonth" );
selectedEndDay = request.getParameter( "endDay" );
selectedEndYear = request.getParameter( "endYear" );

For security reasons we wanted to pass this through a function like this

selectedStartMont = CrossSiteScripting.CrossSiteXYZ(request.getParameter( "startMonth" ));
selectedStartDay = CrossSiteScripting.CrossSiteXYZ(request.getParameter( "startDay" ));
selectedStartYear =CrossSiteScripting.CrossSiteXYZ( request.getParameter( "startYear" ));
selectedEndMonth = CrossSiteScripting.CrossSiteXYZ(request.getParameter( "endMonth" );
selectedEndDay = CrossSiteScripting.CrossSiteXYZ(request.getParameter( "endDay" ));
selectedEndYear = CrossSiteScripting.CrossSiteXYZ(request.getParameter( "endYear" ));

I have nearly 200 files where I have to change like this.Can anyone help me in building a script using awk or sed?
# 2  
Old 06-08-2009
With sed:

Code:
sed 's/\(.*= \)\(.*\);/\1CrossSiteScripting.CrossSiteXYZ(\2);/' file > newfile

With awk:

Code:
awk '{$3="CrossSiteScripting.CrossSiteXYZ("$3;$NF=")"$NF}1' file > newfile

# 3  
Old 06-08-2009
Quote:
Originally Posted by Franklin52
With sed:

Code:
sed 's/\(.*= \)\(.*\);/\1CrossSiteScripting.CrossSiteXYZ(\2);/' file > newfile

With awk:

Code:
awk '{$3="CrossSiteScripting.CrossSiteXYZ("$3;$NF=")"$NF}1' file > newfile


Thanks for that but I should change in the same file

Also I got a sytax error for awk
$ awk '{$3="CrossSiteScripting.CrossSiteXYZ("$3;$NF=")"$NF}1' index.jsp > newfile.txt
awk: syntax error near line 1
awk: bailing out near line 1

While using sed its modiying everything of the format
a= b;

It should be only for
String a= request.getParameter("<anything here>");
or
a=request.getParameter("<anything here>");

to the mentioned above

Last edited by 20033716; 06-08-2009 at 03:45 AM..
# 4  
Old 06-08-2009
If your sed version supports the -i option you can edit the file in place with:

Code:
sed -i 's/\(.*= \)\(.*\);/\1CrossSiteScripting.CrossSiteXYZ(\2);/' file

Otherwise you can do something like::

Code:
sed 's/\(.*= \)\(.*\);/\1CrossSiteScripting.CrossSiteXYZ(\2);/' file > newfile && mv newfile > file

or:

Code:
 awk '{$3="CrossSiteScripting.CrossSiteXYZ("$3;$NF=")"$NF}1' file > newfile  && mv newfile > file

-----Post Update-----

Quote:
Originally Posted by 20033716
Also I got a sytax error for awk
$ awk '{$3="CrossSiteScripting.CrossSiteXYZ("$3;$NF=")"$NF}1' index.jsp > newfile.txt
awk: syntax error near line 1
awk: bailing out near line 1
Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

New to Shell Scripting: Need help interpreting example function

In this example function below, I cannot figure out what certain parts mean. if ! echo $PATHwhat is "if !"? (^|:)$1($|:) What is ^|: and$|:? pathmunge () { if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then if ; then PATH=$PATH:$1 else... (3 Replies)
Discussion started by: MemberName
3 Replies

2. Shell Programming and Scripting

Need help to write a function in shell scripting to execute sql files

Hi, I am new to shell scripting and i need to write a automation script to execute sql files. I need to check the table if it is there in system tables and need to write a function to call the .sql files. For ex. I have a.sql,b.sql,c.sql files, where the sql file contains DELETE and INSERT... (1 Reply)
Discussion started by: Samah
1 Replies

3. Shell Programming and Scripting

Mail function in shell scripting

Hi Guys, i'm new to scripting, please help me to write the script. Purpose: To write a simple addition program and to mail the output result. Script: #!/bin/bash echo "entr numbers"; read n1; read n2; answer=$(($n1+$n2)); echo $answer > mail -s "output" karthic324n@gmail.com; ... (4 Replies)
Discussion started by: Karthick N
4 Replies

4. Shell Programming and Scripting

Script to insert a function into a C source file

Hello, I think I need sed, but perhaps awk could help. I am trying to add a function to a C source file based off a struct declaration. for example: struct Rational { int numerator; int denominator; }; becomes struct Rational (4 Replies)
Discussion started by: afulldevnull
4 Replies

5. Shell Programming and Scripting

Shell Scripting Function call return value

Hi I have a function : Make_Report() { trx_report=`sqlplus -s $conn_str << @@ set echo off; set pages 0; set feedback off; set verify off; select srv_trx_s_no,... (1 Reply)
Discussion started by: neeraj617
1 Replies

6. Shell Programming and Scripting

/usr/bin/time Shell Scripting Function

Hello, I have made a Linux Shell Script that downloads 6 files from the Internet and then deletes them. Now i want to use the function "/usr/bin/time" and "bc" to calculate how long the avergate run time for the shell script is. I therefore need to do it 100 times. My shell script code is below: ... (6 Replies)
Discussion started by: solo2
6 Replies

7. Shell Programming and Scripting

How to insert a sequence number column inside a pipe delimited csv file using shell scripting?

Hi All, I need a shell script which could insert a sequence number column inside a dat file(pipe delimited). I have the dat file similar to the one as shown below.. |A|B|C||D|E |F|G|H||I|J |K|L|M||N|O |P|Q|R||S|T As shown above, the column 4 is currently blank and i need to insert sequence... (5 Replies)
Discussion started by: nithins007
5 Replies

8. Shell Programming and Scripting

connection of JSP using SSH to access Shell script

Hello, I am not sure if I am posting in the right forum. A website is running on a server with <ip1> in unix. It's written in JSP. I need to add a link on the page, which will on-clicking ask for username and password to enter into another server <ip2> and gets all the files from a... (1 Reply)
Discussion started by: shekhar2010us
1 Replies

9. Shell Programming and Scripting

Sed function is shell scripting

Hello everybody, I trying to convert a text inside my file that looks something like this: into hyperlink so that the user can click onto it..... I tried this but doesn't work cat mylist9.html |sed -e '<a href="' >mylist13.html Thanks (13 Replies)
Discussion started by: kev_1234
13 Replies

10. Shell Programming and Scripting

user creation using shell script for JSP

hello friends, I have problem. We want to create user from jsp(browser based) on our linux server. How we can do that ? or How do we create a user with shell programming by taking arguments and checking with the existing users and if the user exist it should display the message the user exists... (1 Reply)
Discussion started by: jarkvarma
1 Replies
Login or Register to Ask a Question