sed - replace backslash linefeed with backslash

Posted on 2011-02-11
Last Modified: 2012-05-11
sed 's/\\\n/\\/g' doesn't work. What should it be?
Question by:modsiw
LVL 40

Expert Comment

ID: 34873420
what do you get when you run command?


sed 's/\\n/\/g'

Author Comment

ID: 34874076
My command doesn't modify the file at all.

Yours doesn't work; blackslash must be escaped.

Author Comment

ID: 34874095
sed 's/\n//g'

doesn't do anything either. I'd expect it to turn the file into a single long line
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

LVL 48

Expert Comment

ID: 34874247
I'd use tr instead

tr -d '\n' <file

Open in new window

LVL 23

Expert Comment

by:Maciej S
ID: 34878766

sed ':L;$!N;s/\n/\\/g;tL'

Open in new window

LVL 23

Accepted Solution

Maciej S earned 500 total points
ID: 34878786
Hmm.. a little bit shorter (and simpler) one:
sed ':L;N;s/\n/\\/;tL'

Open in new window


Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Searching File Names and Eliminating Duplicates in Linux 4 64
Java / Linux and Regular Expressions 11 71
AWS CLI issues with Tags 3 65
Access_log 17 100
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now