I have file like this:Dir1/File1.cpp Dir2/File2.cpp \Dir3/File1.h Dir4/File2.cpp \Dir2/File1.cpp \Dir2/File1.h \I want to generate file like this:Dir1/File1.cppDir2/File2.cppDir3/File1.hDir4/File2.cppDir2/File1.cppDir2/File1.hHow to do this by using Bash/Sed/Awk/Grep or something like this?
How to generate file with all string that match pattern from another file
text processing;sed;awk
If you have an Awk that supports regular expressions for the record separator RS, it can be done like this:awk 'BEGIN { RS =  +| *\\\\?\\n } 1'The advantage of this is that we are not snarfing the entire file into memory and doing some regex replacement; your input could be gigabytes long.We basically treat the file as having two record separators: either one or more spaces, or else zero or more spaces followed by a newline, which may be preceded by an optional backslash.Having delimited the records this way, all we have to do is output them followed by the default output record separator (ORS), which, of course, is newline. That is achieved by a pattern-action rule consisting of 1.Or a pipeline job with sed and tr, not using anything that isn't in POSIX:tr '\n' ' ' | sed -e 's/\\//g' -e 's/ \+/ /g' | tr ' ' '\n'Replace newlines with spaces. Then squash runs of multiple spaces to one space while removing backslashes. Then map spaces to newlines.