Skip to main content
14 events
when toggle format what by license comment
Apr 13, 2017 at 12:36 history edited CommunityBot
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Sep 30, 2016 at 11:54 comment added mikeserv @sylye - $script is the sed script you would use to target whatever portion of your file you wanted; its the script that gets you the end result that you want in stream. v is just a placeholder for an empty line. in a bash shell it is not necessary because bash will automatically use the $REPLY shell variable in its stead if you dont specify one, but POSIXly you should always do so. im glad you find it useful, by the way. good luck with it. im mikeserv@gmail if you need anything in depth. i should have a computer again in a few days
Sep 26, 2016 at 8:01 comment added sylye @mikeserv: I am dealing the same problem as the OP now and I find your solution really useful. But I don't understand the usage of read script and read v in your answer. If you can elaborate more about it I will be much appreciated, thanks!
Dec 29, 2015 at 9:51 comment added mikeserv @Wildcard - if i really wanted it in a variable too, i think id do it like: file=$(sed '/regex/!H;$!d;x' <file | read v && tee file) && cmp - file <<<"$file" || shite so the output file and the var would be written simultaneously, which would make either or an effective backup, which is the only reason you'd wanna complicate things further than you'd need to.
Dec 29, 2015 at 9:37 comment added mikeserv @Wildcard - that could be. but you shouldnt use the shell like a database. the sed | cat thing above never opens output unless sed has already buffered the entire file and is ready to start writing all of it to output. If it tries to buffer the file and fails - read is not successful because finds EOF on the | pipe before it reads its first newline and so cat >out never happens until its time to write it out from memory entirely. an overflow or anything like it just fails. also the whole pipeline returns success or failure every time. storing it in a var is just more risky.
Dec 29, 2015 at 9:32 comment added Wildcard I confess I hadn't read your answer in detail before, because it starts with unworkable (for me) solutions that involve byte count (different amongst each of the many servers) and /tmp which is on the same filesystem. I like your dual sed version. I think a combination of Barmar's and your answer would probably be best, something like: myvar="$(sed '/myregex/d' < file)" && [ -n "$myvar" ] && echo "$myvar" > file ; unset myvar (For this case I don't care about preserving trailing newlines.)
Dec 23, 2015 at 4:54 history edited mikeserv CC BY-SA 3.0
added 253 characters in body
Dec 23, 2015 at 4:30 history edited mikeserv CC BY-SA 3.0
added 562 characters in body
Dec 23, 2015 at 3:50 history edited mikeserv CC BY-SA 3.0
less complicated = mo' betta
Dec 23, 2015 at 3:39 history edited mikeserv CC BY-SA 3.0
deleted 12 characters in body
Dec 23, 2015 at 3:31 history edited mikeserv CC BY-SA 3.0
added 385 characters in body
Dec 23, 2015 at 1:47 history edited mikeserv CC BY-SA 3.0
added 136 characters in body
Dec 22, 2015 at 20:49 history edited mikeserv CC BY-SA 3.0
added 428 characters in body
Dec 22, 2015 at 20:35 history answered mikeserv CC BY-SA 3.0