Search code examples
regexbashsedend-of-linestart-of-line

Regular expression to match beginning and end of a line?


Could anyone tell me a regex that matches the beginning or end of a line? e.g. if I used sed 's/[regex]/"/g' filehere the output would be each line in quotes? I tried [\^$] and [\^\n] but neither of them seemed to work. I'm probably missing something obvious, I'm new to these


Solution

  • Try:

    sed -e 's/^/"/' -e 's/$/"/' file