wader / fq

jq for binary formats - tool, language and decoders for working with binary and text formats
Other
9.79k stars 227 forks source link

-i[ext] like perl #1019

Closed Freed-Wu closed 1 month ago

Freed-Wu commented 1 month ago

I want to use fq to replace perl, such as:

perl -pes=a=b= test.txt
fq -Rr 'sub("a"; "b")' test.txt

However, perl have -i

perl -i.bak -pes=a=b= test.txt
ls test.txt.bak

How can fq support it?

wader commented 1 month ago

Hi, i'm a bit reluctant to add this before jq adds it as i would like to do it in the same way. For jq there has been an attempt to do it that got reverted and there has been some quite lively discussion about it, see https://github.com/jqlang/jq/issues?q=inplace

As i understand it there are some issues and behaviours to think about:

If i would do this i think a first implementation would be first file only (and JSON value not spanning multiple files) and only JSON in/out.

Any ideas how it could work?

Freed-Wu commented 1 month ago

reluctant to add this before jq adds it as i would like to do it in the same way

So we should wait https://github.com/jqlang/jq/issues/105 :smile:

wader commented 1 month ago

Yeah i guess so, sadly it might take some time 😬 but who knows! but would it be ok in your use case if the json get reformatted? (i mentioned comments, but i confused it with reformatting jq code 😄 )