Skip to main content
Removed double-spaced answer and removed single quote
Source Link
garethTheRed
  • 35k
  • 4
  • 101
  • 106

Assuming there areWith no blank lines between each line and no ' character at the start:

$ awk '{print ((NR%2)? "\x27>"">":"\x27""") substr($0,2)}' passages.txt

gives:

'>Sunshine>Sunshine
'ThisThis is a sunny day.
'>Darkness>Darkness
'AA cave is a dark place.

HoweverAlso, if it is double spacedgoing by your responses to all the answers here, then:

$ sed '/^$/d' passages.txt | awk '{print ((NR%2)? "\x27>":"\x27") substr($0,2) "\n" }'

gives:your input file isn't single lines with a Line Feed character at the end (\n). It might be worth checking it's source.

'>Sunshine

'This is a sunny day.

'>Darkness

'A cave is a dark place.

 

Assuming there are no blank lines between each:

$ awk '{print ((NR%2)? "\x27>":"\x27") substr($0,2)}' passages.txt

gives:

'>Sunshine
'This is a sunny day.
'>Darkness
'A cave is a dark place.

However, if it is double spaced, then:

$ sed '/^$/d' passages.txt | awk '{print ((NR%2)? "\x27>":"\x27") substr($0,2) "\n" }'

gives:

'>Sunshine

'This is a sunny day.

'>Darkness

'A cave is a dark place.

 

With no blank lines between each line and no ' character at the start:

$ awk '{print ((NR%2)? ">":"") $0}' passages.txt

gives:

>Sunshine
This is a sunny day.
>Darkness
A cave is a dark place.

Also, going by your responses to all the answers here, your input file isn't single lines with a Line Feed character at the end (\n). It might be worth checking it's source.

Added double-spaced option
Source Link
garethTheRed
  • 35k
  • 4
  • 101
  • 106

Assuming there are no blank lines between each:

$ awk '{print ((NR%2)? "\x27>":"\x27") substr($0,2)}' passages.txt

gives:

'>Sunshine
'This is a sunny day.
'>Darkness
'A cave is a dark place.

However, if it is double spaced, then:

$ sed '/^$/d' passages.txt | awk '{print ((NR%2)? "\x27>":"\x27") substr($0,2) "\n" }'

gives:

'>Sunshine

'This is a sunny day.

'>Darkness

'A cave is a dark place.

 

Assuming there are no blank lines between each:

$ awk '{print ((NR%2)? "\x27>":"\x27") substr($0,2)}' passages.txt

gives:

'>Sunshine
'This is a sunny day.
'>Darkness
'A cave is a dark place.

Assuming there are no blank lines between each:

$ awk '{print ((NR%2)? "\x27>":"\x27") substr($0,2)}' passages.txt

gives:

'>Sunshine
'This is a sunny day.
'>Darkness
'A cave is a dark place.

However, if it is double spaced, then:

$ sed '/^$/d' passages.txt | awk '{print ((NR%2)? "\x27>":"\x27") substr($0,2) "\n" }'

gives:

'>Sunshine

'This is a sunny day.

'>Darkness

'A cave is a dark place.

 
Source Link
garethTheRed
  • 35k
  • 4
  • 101
  • 106

Assuming there are no blank lines between each:

$ awk '{print ((NR%2)? "\x27>":"\x27") substr($0,2)}' passages.txt

gives:

'>Sunshine
'This is a sunny day.
'>Darkness
'A cave is a dark place.