You are not logged in.

#26 2020-12-11 23:06:28

Ashley2020
Banned
Registered: 2020-12-11
Posts: 30

Re: 'Sed' all files in directory by pattern

Oh Lord, why it's not working, just empty string

Offline

#27 2020-12-11 23:09:07

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,656

Re: 'Sed' all files in directory by pattern

It's all okay

Obviously not…

grep data-track-url test.txt

Online

#28 2020-12-11 23:11:00

Ashley2020
Banned
Registered: 2020-12-11
Posts: 30

Re: 'Sed' all files in directory by pattern

seth wrote:

It's all okay

Obviously not…

grep data-track-url test.txt

Yes the grep has returned me a lot of html to the my console

Offline

#29 2020-12-11 23:14:17

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,656

Re: 'Sed' all files in directory by pattern

sed -e '/data-track-url/!d' test.txt

Online

#30 2020-12-11 23:16:23

Ashley2020
Banned
Registered: 2020-12-11
Posts: 30

Re: 'Sed' all files in directory by pattern

seth wrote:
sed -e '/data-track-url/!d' test.txt

Yes that's also shown many HTML strings

Offline

#31 2020-12-11 23:19:40

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,656

Re: 'Sed' all files in directory by pattern

sed -e '/data-track-url=/!d' test.txt
sed -e '/data-track-url="/!d' test.txt

Ah, fuck… again.

sed -e '/data-track-url=/!d; s/.*data-track-url="\([^"]*\)".*/\1/g' test.txt

Online

#32 2020-12-11 23:26:12

Ashley2020
Banned
Registered: 2020-12-11
Posts: 30

Re: 'Sed' all files in directory by pattern

seth wrote:
sed -e '/data-track-url=/!d' test.txt
sed -e '/data-track-url="/!d' test.txt

Ah, fuck… again.

sed -e '/data-track-url=/!d; s/.*data-track-url="\([^"]*\)".*/\1/g' test.txt

I not wont wite but it's also not working big_smile

Like this has return me all page in console:

sed -e '/data-track-url/!d; s/.*data-track-url="\([^"]*\)".*/\1/g' test.txt

Offline

#33 2020-12-11 23:32:15

Ashley2020
Banned
Registered: 2020-12-11
Posts: 30

Re: 'Sed' all files in directory by pattern

The

sed -e '/data-track-url/!d; s/.*data-track-url\([^"]*\)".*/\1/g' test.txt

Returns to me:

</span>=%

Offline

#34 2020-12-11 23:51:11

Ashley2020
Banned
Registered: 2020-12-11
Posts: 30

Re: 'Sed' all files in directory by pattern

Please don't go a way. I really did't get why it not working at all.

Offline

#35 2020-12-12 01:17:16

Ashley2020
Banned
Registered: 2020-12-11
Posts: 30

Re: 'Sed' all files in directory by pattern

After reinstalling arch all working... thanks to zhs...

Offline

#36 2020-12-12 02:26:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,513
Website

Re: 'Sed' all files in directory by pattern

Sed is the wrong tool for the job.  This sed command will get you at most one desired url from every line that has a data-track-url:

sed -n '/data-track-url/{s/.*data-track-url="\([^"]*\)".*/\1/p;}' test.txt

But if there is more than one data-track-url per line (which thre appears to be) this will fail.  The previously attempted use of the 'g' flag for sed will not remedy this.

In this case, piping grep to cut might be the way to go:

grep -o 'data-track-url="[^"]*"' test.txt | cut -d\" -f 2

Last edited by Trilby (2020-12-12 02:30:35)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#37 2020-12-12 09:28:40

GSMiller
Member
Registered: 2020-11-23
Posts: 75

Re: 'Sed' all files in directory by pattern

Ashley, sed is not very good for what you are trying to do, if this is html or xml.
I do not know of ZHS, is this server related?


A dog is a man's best friend.

Offline

#38 2020-12-12 13:56:01

Ashley2020
Banned
Registered: 2020-12-11
Posts: 30

Re: 'Sed' all files in directory by pattern

Trilbyfan wrote:

Ashley, sed is not very good for what you are trying to do, if this is html or xml.
I do not know of ZHS, is this server related?

smile

Offline

#39 2020-12-12 14:00:53

Ashley2020
Banned
Registered: 2020-12-11
Posts: 30

Re: 'Sed' all files in directory by pattern

Trilby wrote:

Sed is the wrong tool for the job.  This sed command will get you at most one desired url from every line that has a data-track-url:

sed -n '/data-track-url/{s/.*data-track-url="\([^"]*\)".*/\1/p;}' test.txt

But if there is more than one data-track-url per line (which thre appears to be) this will fail.  The previously attempted use of the 'g' flag for sed will not remedy this.

In this case, piping grep to cut might be the way to go:

grep -o 'data-track-url="[^"]*"' test.txt | cut -d\" -f 2

Hey do I can this one?

cat * | grep -o 'data-track-url="[^"]*"' test.txt | cut -d\" -f 2

Offline

#40 2020-12-12 14:07:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,513
Website

Re: 'Sed' all files in directory by pattern

Ah ... have you never used a linux/unix system before?  The example was acting on test.txt, if you want it to run on all files (in the current working directory) you replace "test.txt" with the asterisk

grep -o 'data-track-url="[^"]*"' * | cut -d\" -f 2

(edit: did you just change your avatar?  Great, now I'm not the only one with a creepy forum stalker).

Last edited by Trilby (2020-12-12 14:08:42)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB