Phing: append files while adding a newline between them - phing

I'm trying to concatenate several files together using Phing, while leaving a newline between the content of different files. I'm using the append task to concatenate them but I can't figure out how to add the new line. Is there a way to do that without resorting to a custom task?

Following the suggestion of a colleague, I ended up using this:
<filterchain>
<replaceregexp>
<regexp pattern="([^\n])$" replace="$1${line.separator}" ignoreCase="true"/>
</replaceregexp>
</filterchain>
...inside the append task.

Related

i would like to extract the pspictures from a tex file and put the in another file so they can processed into ps or pdf files really easily

I have a list of files .tex file that contain fragments in the tex that build ps pictures which can be slow to process.
There are multiple fragments across multiple files and the end delimiter is \end{pspicture}
% this is the beginning of the fragment
\begin{pspicture}(0,0)(23,5)
\rput{0}(0,3){\crdKs}
\rput(1,3){\crdtres}
\rput(5,3){\crdAh}
\rput(6,3){\crdKh}
\rput(7,3){\crdsixh}
\rput(8,3){\crdtreh}
\rput(12,3){\crdQd}
\rput(13,3){\crdeigd}
\rput(14,3){\crdsixd}
\rput(15,3){\crdfived}
\rput(16,3){\crdtwod}
\rput(20,3){\crdKc}
\rput(21,3){\crdfourc}
\end{pspicture}
I would like to extract the fragments.
I am not sure how to go about this? can awk do this or sed?
They seem to work line by line, rather than work on the whole fragment.
I am not really looking for a solution just a good candidate tool.
sed -En '/^\\begin\{pspicture\}.*$/,/^\\end\{pspicture\}.*$/p' file
Utilising sed with -E for regular expressions.
Use //,// to determine start and ending regular expressions and print all lines from the start to the end.

Use Swift to Delete a Single Line from a Text File

I am using a text file as an XML template for a project I am working on in Xcode with Swift 3. Depending on the type of request I am putting together from the template, sometimes certain lines are not needed. Is there a way in Swift to delete a single line from a text file? My searches are coming up empty.
A little more background: At runtime the contents of the file are copied into an NSString. I do not need to modify the text file itself, just the string that is being instantiated by the file. I have tried doing string.replacingOccurrences(of:string with "") but that is leaving gaps in the file. This actually works, I was just hoping for a more elegant solution.
Change your search and replace criteria to include the white space.
Another alternative would be to use NSRegularExpresssion and stringByReplacingMatchesInString to also remove all surrounding white space.

getting FlatFileParseException when there is empty line in my flat file when doing batch processing with spring-batch

i used the below code for handling it:
<skippable-exception-classes>
<includeclass="org.springframework.batch.item.file.FlatFileParseException"/>
</skippable-exception-classes>
But what is the correct way to handle empty lines in flat file, to avoid seeing the FlatFileParseException, when processing with spring batch.
I think you could accomplish what you're looking for with a custom RecordSeparatorPolicy. You could strip out any empty lines via the RecordSeparatorPolicy#preProcess method and return true in the RecordSeparatorPolicy#isEndOfRecord once you have a record with text. The only gotcha is that you'd have to do some trickery around the use case of if a file had blank lines at the end of the file but I think it's doable.

Perl: How to replace a string in file with a paragraph [duplicate]

This question already has an answer here:
sed find and replace between two tags with multi line
(1 answer)
Closed 8 years ago.
I need to replace a token in a file with a multi-line paragrah, which has several line breakers inside it if the paragraph is represented as a string.
If I use sed the usually for a string to string replacement, the line breakers inside the new string would complain.
So now I want to open the file and seek to that token location, then write the new content into the file from there, but not sure how to achieve that. Can anybody help?
EDIT:
Looks like I probably can put both the file and the content to be inserted as arrays then use splice in perl. Might not be the easiest way though.
perl -i -pe's/token/foo\nbar\nbaz\n/g' file
You can't really insert into a file. Just like inserting into a string, you must first move the remainder of the string out of the way. With files, it's easier just to copy the entire file.
The provided code opens file, deletes file, creates file, then copies (with substitutions) from the open handle to the new handle.
It's my understanding that sed can do this too. It's my understanding that sed also uses -i to enable this feature.
Check out: How do I change, delete, or insert a line in a file, or append to the beginning of a file?
The easiest solutions will be to either use perl's $INPLACE_EDIT, optionally done as a one liner like demonstrated by ikegami, or perhaps to use Tie::File.

Splitting Phing build file

I've got a huge phing build file here. Is there a way to put things like filesets into an external file used by the build.xml? Just need some organisation here.
You can try using the import task, which lets you split a build file into multiple files.
You can also look into property files
FileLists also support a listfile property which is a text file with one file per line.
FileSets support the includesfile and excludesfile property which is a text file with a list of patterns.