Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to escape special characters out of a flowfile?

Solved Go to solution
Highlighted

How to escape special characters out of a flowfile?

Explorer

I have flowfile entries like the following:

{\"CommandLine\":\"/bin/sh -c ( LC_MESSAGES=C;export LC_MESSAGES;df -k | awk 'NF == 1 { printf $0; next } { print }' ) > /opt/netiq/netiq/AM/tmp/netiqKykswU\",\"ConfigBuild\":\"1007.8.0010402.9\",\"ConfigStateHash\":\"788983332\",\"Entitlements\":\"15\",\"GID\":\"0\",\"ImageFileName\":\"/usr/bin/bash\",\"MD5HashData\":\"0883bc66ffeba0e89ee0a753ddbc1950\",\"NDRoot\":\"313466589192688920\",\"ParentBaseFileName\":\"agent\",\"ParentProcessId\":\"313467877387179481\",\"ProcessEndTime\":\"1602877133.023\",\"ProcessGroupId\":\"313466594618021306\",\"ProcessStartTime\":\"1602877133.016\",\"RGID\":\"0\",\"RUID\":\"1420\",\"RawProcessId\":\"52404\",\"SHA1HashData\":\"0000000000000000000000000000000000000000\",\"SHA256HashData\":\"c1c73170d33c0319a795bb05b1dbe7884b7582ec9f696d8a795e0ce692cb714e\",\"SVGID\":\"0\",\"SVUID\":\"1420\",\"SessionProcessId\":\"313467877387179481\",\"SourceProcessId\":\"313467877387179481\",\"SourceThreadId\":\"0\",\"TargetProcessId\":\"317237720018782501\",\"UID\":\"1420\",\"aid\":\"5b13c4513710431846be50a7840630aa\",\"aip\":\"164.95.95.156\",\"cid\":\"dbd8aea753b140cfa86a0e4d85d2dbb0\",\"event_platform\":\"Lin\",\"event_simpleName\":\"ProcessRollup2\",\"id\":\"39244150-0fe7-11eb-ba54-0a51f8dd8adc\",\"name\":\"ProcessRollup2LinV6\",\"timestamp\":\"1602877133547\",\"ComputerName\":\"testdata\"}"}

The highlighted section demonstrates a portion that has special characters that are not escaped.  This is causing problems downstream.  How do I escape those characters without double escaping others that are OR escaping the FIRST { or the LAST }

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

I know what you asked for... but this is what you really need

Explorer

In this case the problem isn't escaping the special characters in the middle of the flowfile, instead an efficient use of the ReplaceText processor was needed.  As it turns out the only real need was to add a comma after the last '}' of every line except the last.  ReplaceText handles this nicely and gives me the opportunity to inspect the objects line-by-line instead of the entire text.  This is accomplished with setting the Search Value: }$ (this means find a } but only if it's at the end of the line) and then setting the Replacement Value: }, replacing the } character with another but appending a comma to the end.

 

By inspecting line by line it also reduces resources required.

Kilynn_0-1602947459753.png

 

 

View solution in original post

1 REPLY 1
Highlighted

I know what you asked for... but this is what you really need

Explorer

In this case the problem isn't escaping the special characters in the middle of the flowfile, instead an efficient use of the ReplaceText processor was needed.  As it turns out the only real need was to add a comma after the last '}' of every line except the last.  ReplaceText handles this nicely and gives me the opportunity to inspect the objects line-by-line instead of the entire text.  This is accomplished with setting the Search Value: }$ (this means find a } but only if it's at the end of the line) and then setting the Replacement Value: }, replacing the } character with another but appending a comma to the end.

 

By inspecting line by line it also reduces resources required.

Kilynn_0-1602947459753.png

 

 

View solution in original post

Don't have an account?
Coming from Hortonworks? Activate your account here