Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
talendtester
Creator III
Creator III

tSystem - sed command - I am close, just need a little help

@lli

 

When I am in the command line, this command works on Windows for using the GNU sed:

sed -i ":a;N;$!ba;s/\"\n\"«/\"\"«/g" myFile.csv

 

I have a 115GB file which has multiple row which are breaking to multiple lines.

I need to find and replace all occurrences of double quote new line character double quote and special character « (which is my delimiter).

 

For example:

line_one_here"\n
the_rest_of_line_one_here

line_two_here

line_three_here

 

I am trying to get this to work in tSystem:

"sed -i \":a;N;$!ba;s/\"\n\"«/\"\"«/g\" "+ context.myFile

 

Error is:

sed: -e expression #1, char 12: unterminated `s' command

 

Similar to this post:

https://community.talend.com/t5/Design-and-Development/Not-able-to-run-Linux-command-using-tSystem-C...

Labels (3)
6 Replies
Anonymous
Not applicable

Whats wrong with the line breaks?

It is not a problem for parsing CSV!

If the values are capsulated in an exclosure like " the line break does not disturb will be treated simple as content.

talendtester
Creator III
Creator III
Author

The problem is when the 115GB file was created, the .csv option wasn't turned on 0683p000009MPcz.png

Anonymous
Not applicable

I have done a quick check what is the result of your sed java expression:

In a tJava:

System.out.println("sed -i \":a;N;$!ba;s/\"\n\"«/\"\"«/g\" ");

The result is:

sed -i ":a;N;$!ba;s/"
"«/""«/g" 

It does not looks like your original working command line above.

Your problem is the line break misused currently. Try this as java expression in the tSystem component.

"sed -i \":a;N;$!ba;s/\\\"\\n\\\"«/\\\"\\\"«/g\" "

compared to your working command from your post:

sed -i ":a;N;$!ba;s/\"\n\"«/\"\"«/g"

this is the result of my changed java escaped command line:

sed -i ":a;N;$!ba;s/\"\n\"«/\"\"«/g"

I suggest you are trying your expression and print it out with System.out.println and tweak it until it looks like your expected command line.

talendtester
Creator III
Creator III
Author

I think this works:

context.myCommand="sed -i \":a;N;$!ba;s/\\\"\\n\\\"«/\\\"\\\"«/g\"
myFile.csv";
System.out.println(context.myCommand);
Anonymous
Not applicable

Where the hell is my response? I have for about an hour send your exactly this answer!


@talendtester wrote:
I think this works:

context.myCommand="sed -i \":a;N;$!ba;s/\\\"\\n\\\"«/\\\"\\\"«/g\"
myFile.csv";
System.out.println(context.myCommand);

 

talendtester
Creator III
Creator III
Author

@lli thank you for your fast help! 

 

Not sure, I got the email update notice and I attempted to respond to it (instead of the earlier post) but the forums gave me a message saying I didn't have permissions and then when I refreshed the page your newer post was gone.