sed -e:t -e'y/\n/ /;/\\{{\[}/!b' \ -e:N -e'/\\{{\[.*{\]}\\}/!N' \ -e's/\(\\{{\[}\).*\n/\1/;tN' \ -e'y/ /\n/;s/\\{{\[}/& /;ts' \ -e:s -e's/\(\[} [^ ]*\)\({\]}\\}\)/\1 \2/' \ -ets -e's/..... [^ ]* .....//;s/ //g;bt' \ <<"" #Bla Bla {]}\} bla bla \{{[} more bla bla #even more bla bla bla bla. \{{[} # #A lot of stuff might be here. #hashes are for stupid syntax color only #Bla bla {]}\} finally {]}\} done. # #Nonetheless, the \{{[} show {]}\} goes \{{[} show {]}\} on.
#Bla Bla {]}\} bla bla finally {]}\} done. # #Nonetheless, the goes on.
Но вот гораздо лучший способ. Гораздо меньше замен, и те, которые сделаны для пары символов за раз, а не
. *
все время. Практически единственный раз. *
используется для очистки образца пространства между пространствами, когда первый происходящий старт определенно сопряжен с первым последующим концом. Все остальное времяsed
простоD
удаляет столько, сколько нужно для того, чтобы добраться до следующего встречающегося разделителя. Дон научил меня этому.sed -etD -e:t -e'/\\{{\[}/!b' \ -e's//\n /;h;D' -e:D \ -e'/^}/{H;x;s/\n.*\n.//;}' \ -ett -e's/{\]}\\}/\n}/' \ -e'/\n/!{$!N;s//& /;}' -eD \ <<"" #Bla Bla {]}\} bla bla \{{[} more bla bla #even more bla bla bla bla. \{{[} # #A lot of stuff might be here. #hashes are for stupid syntax color only #Bla bla {]}\} finally {]}\} done. # #Nonetheless, the \{{[} show {]}\} goes \{{[} show {]}\} on.
#Bla Bla {]}\} bla bla finally {]}\} done. # #Nonetheless, the goes on.
RHS
\n
ewline побегов, возможно, потребуется заменить на литеральные убранные новые строки.Вот более общая версия:
#!/usr/bin/sed -f ####replace everything between START and END #branch to :Kil if a successful substitution #has already occurred. this can only happen #if pattern space has been Deleted earlier t Kil #set a Ret :label so we can come back here #when we've cleared a START -> END occurrence #and check for another if need be :Ret #if no START, don't /START/!b #sigh. there is one. get to work. replace it #with a newline followed by an S and save #a copy then Delete up to our S marker. s||\ S| h;D #set the :Kil label. we'll come back here from now #on until we've definitely got END at the head of #pattern space. :Kil #do we? /^E/{ #if so, we'll append it to our earlier save #and slice out everything between the two newlines #we've managed to insert at just the right points H;x s|\nS.*\nE|| } #if we did just clear START -> END we should #branch back to :Ret and look for another START t Ret #pattern space didnt start w/ END, but is there even #one at all? if so replace it w/ a newline followed #by an E so we'll recognize it at the next :Kil s|END|\ E| #if that last was successful we'll have a newline #but if not it means we need to get the next line #if the last line we've got unmatched pairs and are #currently in a delete cycle anyway, but maybe we #should print up to our START marker in that case? /\n/!{ #i guess so. now that i'm thinking about it #we'll swap into hold space, and Print it ${ x;P;d } #get next input line and add S after the delimiting #newline because we're still in START state. Delete #will handle everything up to our marker before we #branch back to :Kil at the top of the script N s||&S| } #now Delete will slice everything from head of pattern space #to the first occurring newline and loop back to top of script. #because we've definitely made successful substitutions if we #have a newline at all we'll test true and branch to :Kil #to go again until we've definitely got ^E D
... без комментариев...
#!/usr/bin/sed -f t Kil :Ret /START/!b s||\ S| h;D :Kil /^E/{ H;x s|\nS.*\nE|| } t Ret s|END|\ E| /\n/!{ ${ x;P;d } N s||&S| } D
Я скопировал комментированную версию в буфер обмена и сделал:
{ xsel; echo; } >se.sed chmod +x se.sed ./se.sed
#!/usr/bin/sed -f ####replace everything between #branch to :Kil if a successful substitution #has already occurred. this can only happen #if pattern space has been Deleted earlier t Kil #set a Ret :label so we can come back here #when we've cleared a occurrence #and check for another if need be :Ret #if no at the head of #pattern space. :Kil #do we? /^E/{ #if so, we'll append it to our earlier save #and slice out everything between the two newlines #we've managed to insert at just the right points H;x s|\nS.*\nE|| } #if we did just clear we should #branch back to :Ret and look for another , but is there even #one at all? if so replace it w/ a newline followed #by an E so we'll recognize it at the next :Kil s|END|\ E| #if that last was successful we'll have a newline #but if not it means we need to get the next line #if the last line we've got unmatched pairs and are #currently in a delete cycle anyway, but maybe we #should print up to our
-121--81983-
Я не был уверен, следует ли мне просто удалить этот вопрос, потому что он оказался очень распространенной проблемой прокси.
Я был убежден, что это не так, но делая wget-O- http://cdn.debian.net/debian/dists/jessie/InRelease , как предложено, вернул ответ от нашего прокси. Я не думал, что указывал на нашего доверенного лица, но это так!
-121--228698-
У меня есть Fedora 23 (не бета) в качестве гостя виртуальной коробки, и у меня была та же проблема, и я сделал это:
sudo dnf --showduplicates --allowerasing --releasever=22 downgrade xorg-x11-server-Xorg
А затем я переустановил дополнения гостя и все было хорошо, Fedora гость работает с полным разрешением экрана. Я нашел вышеуказанное решение здесь: http://forums.fedoraforum.org/showthread.php?t=306857 . В основном это понижение уровня X-Server.
for file in /dir/*.txt; do
mv "$file" "${file%_*}_Others.txt"
done
${file%_*}
— это форма расширения параметров оболочки, которая удалит все, начиная с последнего _
и далее.
С помощью инструмента Perl rename
при условии, что вы находитесь в том же каталоге, что и файлы, которые необходимо переименовать:
rename 's/_Control1[68]/_Others/' GE.*_Control1[68].txt
Если вам нравится немного запутанности, вот еще один способ:
paste <(ls) <(ls | sed 's/_Control1[68]/Others') | sed 's/^/mv /' | bash
Во-первых, попробуйте запустить конвейер без bash. :-)Я предполагаю, что в каталоге нет других файлов. Если есть, замените каждый ls
на ls *Controll1[68].txt
или что-то подобное, чтобы ограничить список.
"I'd rather write programs that write programs than write programs" - Richard Sites
(Я мог бы поклясться, что это был Алан Перлис, но Google с этим не согласен ).