Timeline for How does -e work in sed?
Current License: CC BY-SA 4.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
17 hours ago | comment | added | Ed Morton |
Aside: sed is great for simple substiutions on individual lines but for anything else an awk script is usually some combination of clearer, simpler, more robust, more portable, etc. In this case awk -v ORS= '{gsub(/-/,"_"); print} END{if (NR) print RS}' input.txt would do what you want in any awk without relying on an arcane pile of single-character instructions and without reading all of the input into memory and so would work for arbitrarily large input.
|
|
yesterday | history | edited | glacier | CC BY-SA 4.0 |
fix question
|
yesterday | history | became hot network question | |||
yesterday | answer | added | Stéphane Chazelas | timeline score: 3 | |
yesterday | comment | added | glacier |
@Raffa It works... I tried using \n but I didn't work without the -z option. For future reference: unix.stackexchange.com/q/26284/589116
|
|
yesterday | comment | added | Raffa |
FWIW re: "I want to substitute - with _ and join the two lines" ... sed -z 's/-/_/g; s/\n//g' should do what you want at least with GNU sed.
|
|
yesterday | history | edited | terdon♦ | CC BY-SA 4.0 |
minor fixes
|
yesterday | vote | accept | glacier | ||
yesterday | comment | added | cas | related, but not a dupe: Make multiple edits with a single call to sed | |
yesterday | comment | added | cas | how does your sample input.txt differ from the actual file you want to modify? does it contain only two lines? if it contains more than two lines, do you want to merge all lines together? or join every second line to the previous line? or something else? do you need to insert a space or tab between the joined lines? | |
yesterday | comment | added | Stéphane Chazelas |
Note: In several sed implementations including the original one, :a; N; $!ba; s/\n//g' is to define a label called a; N; $!ba .
|
|
yesterday | answer | added | DineshS | timeline score: 2 | |
yesterday | answer | added | Stephen Kitt | timeline score: 10 | |
yesterday | history | asked | glacier | CC BY-SA 4.0 |