Tag Info

New answers tagged

0

sed always removes the trailing \newline just before populating pattern space, and then appends one before writing out the results of its script. A \newline can be had in pattern-space by various means - but never if it is not the result of an edit. This is important - \newlines in sed's pattern space always reflect a change, and never occur in the input ...


0

Alternatively, you can use a slightly simpler syntax: sed ':a;N;s/\n/,/g;ba' ...just changing sequence order.


1

The main use of minicom during its heyday was for talking to modems which understood the Hayes command set (AT commands). AT commands are terminated by carriage return. It was convenient to be able to type ATDT5550123 Enter and have the correct command terminator sent to the modem.


7

Yes, this happens because it is a "partial line". And by default zsh goes to the next line to avoid covering it with the prompt. When a partial line is preserved, by default you will see an inverse+bold character at the end of the partial line: a "%" for a normal user or a "#" for root. If set, the shell parameter PROMPT_EOL_MARK can be used to ...


2

Here's a pure bash approach that will delete the first newline of every pair: command | while IFS="\n" read i; do let c++; [ "$(expr $c % 2)" -eq "0" ] && echo "$i" || printf "%s " "$i"; done If you don't need to keep the whitespace unchanged, you can leave out the IFS: command | while read i; do let c++; [ "$(expr $c % 2)" -eq ...


4

Try this: sed -e ':1' -e 'N' -e '$!b1' -e 's/\n/ /g'


4

Easyest ssh user@system command | tr '\n' ' ';echo Or if you want sed ssh user@system command | sed 'N;s/\n\s\+/ /'


0

The newlines were lost, because the shell had performed field splitting after command substitution. In POSIX Command Substitution section: The shell shall expand the command substitution by executing command in a subshell environment (see Shell Execution Environment) and replacing the command substitution (the text of command plus the enclosing ...


-2

The newlines are replaced with spaces because that's how echo works - it concatenates its arguments on spaces. echo replaces argument delimiters with a space. In truth, you can iterate with for over anything you want, but you have to specify the field delimiter first: string=abababababababababababa IFS=a for c in $string do printf %s "$c" done ...


2

To add my emphasis, for loops iterate over words. If your file is: one two three four Then this will emit four lines: for word in $(cat file); do echo "$word"; done To iterate over the lines of a file, do this: while IFS= read -r line; do # do something with "$line" <-- quoted almost always done < file


2

You can use read from bash. Also look for the mapfile while read -r link do printf '%s\n' "$link" done < links.txt Or using mapfile mapfile -t myarray < links.txt for link in "${myarray[@]}"; do printf '%s\n' "$link"; done


4

Newlines get swapped out at some points because they are special characters. In order to keep them, you need to make sure they're always interpreted, by using quotes: $ a="$(cat links.txt)" $ echo "$a" link1 link2 link3 Now, since I used quotes whenever I was manipulating the data, the newline characters (\n) always got interpreted by the shell, and ...



Top 50 recent answers are included