0

I have a file with the many links like this:

http://example.com/mall/mall/detail3.jsp?proID=2114280
http://example.com/mall/member/member/bookshelves/add.jsp?proID=3354136&productName=something
http://example.com/mall/bestbookTW//mall/detail3.jsp?proID=3435839&c=532166&id=954325

And I want it to become this:

http://example.com/mall/mall/detail3.jsp?proID=FUZZ
http://example.com/mall/member/member/bookshelves/add.jsp?proID=FUZZ&productName=FUZZ
http://example.com/mall/bestbookTW//mall/detail3.jsp?proID=FUZZ&c=FUZZ&id=FUZZ

How can I do this with sed or grep or awk?

2
  • 1
    Between which symbols?
    – RudiC
    Jan 12, 2020 at 12:21
  • @RudiC Between = and (& or line break).
    – Nepumuk
    Jan 12, 2020 at 13:12

2 Answers 2

1

Try also

awk 'gsub("=[^&]*", "=FUZZ")' file 
http://example.com/mall/mall/detail3.jsp?proID=FUZZ
http://example.com/mall/member/member/bookshelves/add.jsp?proID=FUZZ&productName=FUZZ
http://example.com/mall/bestbookTW//mall/detail3.jsp?proID=FUZZ&c=FUZZ&id=FUZZ
0

A perl approach:

$ perl -pe 's/=(.+?)(&|$)/=FUZZ$2/g' file 
http://example.com/mall/mall/detail3.jsp?proID=FUZZ
http://example.com/mall/member/member/bookshelves/add.jsp?proID=FUZZ&productName=FUZZ
http://example.com/mall/bestbookTW//mall/detail3.jsp?proID=FUZZ&c=FUZZ&id=FUZZ

The idea is to replace all strings following a = and until the next & or the end of the line ($) with FUZZ.

To modify the original file instead of printing to standard output, use -i:

perl -i -pe 's/=(.+?)(&|$)/=FUZZ$2/g' file 

Alternatively, with sed:

$ sed -E 's/=([^&]*)/=FUZZ/g' file 
http://example.com/mall/mall/detail3.jsp?proID=FUZZ
http://example.com/mall/member/member/bookshelves/add.jsp?proID=FUZZ&productName=FUZZ
http://example.com/mall/bestbookTW//mall/detail3.jsp?proID=FUZZ&c=FUZZ&id=FUZZ

Again, use -i to edit the original file:

sed -i -E 's/=([^&]*)/=FUZZ/g' file 

And you can use the same approach with perl too:

perl -i -lpe 's/=([^&]*)/=FUZZ/g' file 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .