New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
saving the content of a file modified inline with to text
erases the content
#9456
Comments
Actually I don't think we have a way to fix it. nushell handles So your pipeline is basically like this: So the result will be empty. To work aound this, you have to either:
let x = (open file.txt --raw | lines | find --invert --regex '^\s*$' | to text)
$x | save -f file.txt
open file.txt --raw | lines | find --invert --regex '^\s*$' | to text | complete | get stdout | save -f file.txt |
@WindSoilder yeah i've been able to fix my issue with #!/usr/bin/env nu
def main [file: path] {
let content = (open $file --raw)
$content
| lines
| find --invert --regex '^\s*$'
| to text
| save --force $file
}
|
not sure how to qualify this issue then, as wontfix? |
Yeah, I'd vote for wontfix |
@WindSoilder in the i think it's worth reopening |
to text
erases the content
i wrote |
@fdncred |
maybe? i stole that from somewhere else probably. I think the real question isn't is this a fix or won't fix. it's do we think this is working the way we want it to. if it's not, then we should fix it. if it is working the way we want it to, because the work-around is the idiomatic solution, then we shouldn't fix it. |
@fdncred imo the fact that #!/usr/bin/env nu
def main [file: path] {
open $file --raw
| lines
| find --invert --regex '^\s*$'
| to text
| save --force $file
} does not work but #!/usr/bin/env nu
def main [file: path] {
open $file --raw
| lines
| find --invert --regex '^\s*$'
| str join "\n"
| save --force $file
} does is confusing 🤔 |
Describe the bug
i wanted to write a script to modify a bunch of config files of mine at once.
for the example, let's say i want to remove all the empty lines from a file and save the file inplace with the lines removed.
i should be able to use the following script
however the content of the file gets erased completely...
How to reproduce
PATH
asremove-empty-lines-inplace
file.txt
replace-empty-lines-inplace file.txt
file.txt
is now emptyExpected behavior
i expected the content of
foo.txt
to beafter running
remove-empty-lines-inplace
Screenshots
No response
Configuration
Additional context
No response
The text was updated successfully, but these errors were encountered: