Remove Last Character of Each Line

I had to modify a file for loading into an Oracle database with SQL*Loader. The file was using as field delimiter the | pipe character and each line was ending in a |. So ideally, I would like to remove the pipe chracter that ends each of the 384 016 850 lines of my text file.

One option is to use vim macros but I chose to use sed. The Linux command that would work is:

sed -i 's/.$//' filename

but I noticed with surprise that this command would not work in mac OS!
After a bit of investigation, I found out that the sed implementation on macOS is a bit different so the command on macOS is:

sed -i '' 's/.$//' filename

note the extra characters that make the difference!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s