i want to remove the line breaks in a text file using perl script

enter image description here

can this be achieved using perl one liners?

1

1 Answer

You can use

perl -pne '$_=~s/\n//g; $_=~s/\+//g; END{print "\n";}' filename.txt

Explanation:

  • perl -pne reads the file line-wise, performs the commands given and outputs the content of $_
  • comp; removes the newline character at the end of the line
  • $_=~s/\+//g; removes the + sign from the line
  • END{print "\n";} adds a newline at the end of the file

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like