Visit Our UNIX and Linux User Community

Combining two perl commands into one

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combining two perl commands into one
# 15  
Old 04-09-2020
Hi @bedtime
thank you. Indeed, translating into French is much more complicated.
I tagged a release in v2.0.0 with support for multi-line subtitles.
Maybe this will change the situation? In addition, in the .txt file for the translation,
I put a semicolon (only in the develop branch; you can use a period, just change this in the 112 line).
It gave out only 2 errors because Google translated the numbers in the 6th line and 9th

The .ass file will also have one line but separated by \N.
In the .txt files, lines without numbers belong to the subtitle upward number.
I want to remind you that if a stop occurs, it is better to exit the program
to edit the file according to the suggested prompts and after restarting the program
it will continue to execute from where it was stopped. Again, the same test will pass
and if there are any uncorrected errors, you can endlessly remain at the same level of program execution.
Try it very conveniently.
I can't try the point "." because I was again banned in Google Smilie and even 'torsocks' does not help
Combining two perl commands into one-errorpng
Combining two perl commands into one-breakpointpng
Combining two perl commands into one-error1png
Combining two perl commands into one-error2png

Last edited by nezabudka; 04-09-2020 at 07:03 AM..
This User Gave Thanks to nezabudka For This Post:
# 16  
Old 04-09-2020
I wanted to try to write everything in an AWK script, but it's not so easy to encode utf-8 text in URLs through AWK
awk -F '",["n]' '
  text = "I%20do%20not%20know%20how%20to%20encode%20a%20text%0Ain%20an%20awk%20for%20a%20url%20request"
  HttpService = "/inet/tcp/0/"
  print "GET" text |& HttpService
  while ((HttpService |& getline) > 0)
     if($0 ~ /^[,[]+"/ ) {sub(/^[,[]+"/, "", $1); print $1, "==", $2} 

Last edited by nezabudka; 04-09-2020 at 07:22 AM..
# 17  
Old 04-09-2020
I can't try the point "." because I was again banned in Google Smilie and even 'torsocks' does not help
If Google bans me when I'm using method #1 (below), I simply use method #2, and vice-versa.

Method #1 translation=$(wget -U "Mozilla/5.0" -q -O- "$source_lang&tl=$target_lang&dt=t&q=$line" | perl -lne 'push @a,/(?<!\,\[\[)\[\"(.*?)(?<!\\)\"/g;END{print "@a"}' | perl -CS -pwe 's/\N{U+005C}\N{U+0022}\s?/\N{U+0022}/g;')

Method #2 translation=$(trans -s en -t fr -b "$line")

Perhaps method #2 uses an API and Google sees it as a separate thing? Anyways, it's always worked for me. I must caution you that you cannot safely translate in bulk more often than every 12 seconds. You may get away with it for several rounds, but you will inevitably be banned. You have this set to 2 seconds. It bans me when I follow your default.

I wanted to try to write everything in an AWK script, but it's not so easy to encode utf-8 text in URLs through AWK

For something like this, I would highly recommend Perl; it's much more powerful and was made to handle all kinds of file formats that awk and sed can't do. Awk and sed cannot even do a REGEX look-behind.

I've been at the computer for hours, so I'm taking a break. I'll test your fixes when I'm refreshed (tonight or tomorrow).
# 18  
Old 04-10-2020
I've attached the results. None of the subtitles seemed to translate properly. At least with me. I made sure to get rid of the '\r' on each .srt file with your code.

All the above files worked with my new program with about 99.98% accuracy (998/1000 were fine). I'm going to guess that awk is messing things up in your program, but I'm not sure. French, like you said, is harder to translate, but it is essential to be able to use French as it comes up so often.

I will continue to test if as you update. If you need anymore information, please just ask.


So frustrating. In my program, Google Translate really cannot be depended upon to give you back information exactly as you sent it:

 ((1)) I'd been living with Marianne almost 3 years ((2)) in an apartment belonging to her. ((3)) Things were fine between us, till she said one day: ((4)) Got a second? ((5)) Yes, why? ((6)) To tell you something, but it may be a bad time. ((7)) Go on, say it. What's wrong? ((8)) I'm pregnant. ((9)) You're pregnant... ((10)) That's great. ((11)) Is it a problem for you? ((12)) Abel... ((13)) I'm pregnant, but not from you. ((14)) What? ((15)) I'm not pregnant from you. ((16)) So... from who then? ((17)) Paul. ((18)) You had a thing with Paul? ((19)) Yes. ((20)) Since when? ((21)) A little over a year. ((22)) But Paul is someone... ((23)) so... ((24)) So what? ((25)) So different, so... ((26)) Different from who? ((27)) I don't know... you know Paul's family. ((28)) They know. ((29)) If you've seen his family, what does it mean? ((30)) It means we may have to get married. ((31)) It means a lot to his parents. ((32)) Yes, they're a bit conventional, but... ((33)) You haven't chosen a date? ((34)) It's been saved. ((35)) Paul wants you to come. ((36)) Unless it bothers you. It's up to you. ((37)) When is it? ((38)) The 26th. ((39)) Of this month? ((40)) We prefer to act quickly, because of... ((41)) You want me to pack my stuff? ((42)) You still have time, but before the 26th is best. ((43)) What's today? ((44)) The 16th. ((45)) I have to go. I'll be late. ((46)) Maybe it wasn't the right time to tell you. ((47)) I'm glad you're taking it well. ((48)) He thought you'd be angry. ((49)) I kept reassuring him. ((50)) Can he call you today? ((51))


((1)) C'était comme si nous vivions ensemble. ((2)) Je me souviens, ((3)) un jour, il a laissé sa voiture déverrouillée. ((4)) J'ai même ... ((5)) Attends, qu'est-ce que je dis? ((6)) C'était avant. J'étais plus jeune. ((7)) Quoi qu'il en soit, j'ai ouvert la porte ... ((8)) et j'ai pris une photo de moi à l'intérieur, ((9)) comme si j'étais à côté de lui et qu'il conduisait. ((10)) Je m'imaginais aller à Venise. ((11)) Lors de notre lune de miel. ((12)) Ce jour-là, j'ai pensé: ((13)) 'Il m'a vu à coup sûr. ((14)) Nous sommes un couple. Nous sommes amoureux. Nous partons ensemble. ((15)) Le Il s'est enfui. Il ne m'avait pas vu. ((16)) Il était en retard au travail. ((17)) Ce jour-là, ((18)) sans argent pour un ticket de métro, ((19)) Je suis rentré à pied de la banlieue. ((20)) Je détestais Marianne de l'avoir pris de moi. ((21)) quand elle a choisi mon frère Paul. '((23)) Mais quand Marianne a quitté Abel, ((24)) il a bougé et je l'ai perdu de vue. ((25)) Pendant les cinq années suivantes, ((26)) je n'ai pas vu Abel. ( (27)) Bien sûr, j'ai eu quelques aventures, ((28)) mais aucune mérite d'être racontée. ((29)) Maintenant que j'y pense, tout ce temps, ((30)) je n'ai bien fait qu'une chose. ((31)) J'ai grandi. ((32)) Puis un jour, par hasard, j'ai vu Abel. ((33)) Je suis Eve, la sœur de Paul. ((34)) Bonjour, Eve. ((35 )) Vous avez grandi. ((36)) Merci. ((37)) - Ça va? - Je vais bien. ((38)) Et vous? N'avez-vous pas fait du théâtre? ((39)) Oui, mais je me suis arrêté au théâtre. ((40)) Je ' m dans l'immobilier maintenant. ((41)) Tu gèle. ((42)) Vos dents claquent. ((43)) Êtes-vous occupé maintenant? ((44)) Je suis en retard. Je dois y aller. ((45)) Je vais déposer ton écharpe. ((46)) Non, c'est un cadeau, d'accord? ((47)) Bonne journée, amoureux. ((48)) À bientôt ... ((49)) Au revoir, Eve. ((50)) Pas même un amant, ((51))

Where is ((22))? Gone. Google Translate ate it. If I decrease the number of chunks sent to Google then ((22)) comes back, but that is not a dependable solution. If I use single brackets around the numbers, several similar problems arise with the text.

*brain explodes*

Last edited by bedtime; 04-12-2020 at 03:35 PM..
This User Gave Thanks to bedtime For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #329
Difficulty: Easy
The NVidia named the GTX 1080 because it can only render at a 1920x1080 screen resolution.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining 2 commands

Hello all, I need to send an attachment and text in the body, both in the same Email. Below are two cammand that send the required data in separate Emails. I need to combine them so that I get just 1 Email containing the attachment & text in the body. uuencode ${filename} "${file_}" |... (6 Replies)
Discussion started by: Junaid Subhani
6 Replies

2. Shell Programming and Scripting

How to combining awk commands?

I can achieve two tasks with 2 different awk commands: 1) awk -F";;WORD" '{print $2}' file | sed '/^$/d' #to find surface_word 2) awk -F"bw:|gloss:" '// {print $2}' file | sed '/\//!d; s:/*+*: + :g; s:^+::; s: *+ *$::;' #to find segmentation of surface_word Number 1) finds surface_word... (7 Replies)
Discussion started by: Viernes
7 Replies

3. UNIX for Dummies Questions & Answers

Help with combining the ls and 'file' commands

I have a directory of 3000 files without extensions (Solaris 5.10). I would like to iterate the file names through the 'file' command and output their mime types (most are pdf or jpg, but a very few might be psd or swf which show simply as 'data') So, I would like the output of the 'ls'... (2 Replies)
Discussion started by: pwallace
2 Replies

4. UNIX for Dummies Questions & Answers

Combining resukts of ls commands

Hi, I have a directory with some XML files in it. I can use wildcards to get the list of XMLs I want say I have following XMLs in same dir Employee1.xml Employee2.xml Employee3.xml and Salary1.xml Salary2.xml Salary3.xml apart from other .txt .dat files etc I want to write a unix... (7 Replies)
Discussion started by: dsrookie
7 Replies

5. UNIX for Dummies Questions & Answers

Combining two commands that use sar.

hey can anyone tell me how can i combine these two commands so that it is executed only once, but gives me both the results. IDLE=`sar 30 6 | grep Average | awk '{print $1 $5}' ` sar 30 120 | awk '{print $1" "$5}' >> mailx -m -s "$MSG" (5 Replies)
Discussion started by: Ankur Khatri
5 Replies

6. Shell Programming and Scripting

Combining multiple commands

Hi Guys, I am looking to optimze these 5 SSH lines to a single SSH to get my machine to not hang! lol! cat hosts.lst | xargs -n1 -t -i echo 'home/util/timeout 6 0 ssh -q {} top -b > util/{}.top &' >> r_query_info cat hosts.lst | xargs -n1 -t -i echo 'home/util/timeout 6 0 ssh -q {} uname -r... (5 Replies)
Discussion started by: wick3dsunny
5 Replies

7. UNIX for Advanced & Expert Users

Combining two commands.

Is there anyway to achieve "find /home -name "*.bashrc" 2>/dev/null" and "PS1="\n>"" in the same command? I just wanna add a line to the previous command to change the PS1 variable to ">". (1 Reply)
Discussion started by: raidkridley
1 Replies

8. UNIX for Dummies Questions & Answers

combining commands

Hello all, I am trying to list and count all the files of a particular type in any given directory. I can use the commands separately but when I combine them they do not give an output. The command for counting the files is ls -1 | wc -l and for listing all the file of particular type say... (2 Replies)
Discussion started by: BigTool4u2
2 Replies

9. UNIX for Dummies Questions & Answers

combining sed commands

I would like to change the lines: originalline1 originalline2 to: originalline1new originalline1newline originalline2new originalline2newline To do this, id like to combine the commands: sed 's/^/&new/g' file > newfile1 and sed '/^/ a\\ newline\\ \\ (2 Replies)
Discussion started by: Dave724001
2 Replies

10. UNIX for Dummies Questions & Answers

Combining elements of different commands in history

What is the correct format for a single command that would combine portions of 2 different lines in the command history? I'm using a C shell. Here's a simplified command history to clarify: 4 rm file1 5 ls -ld file2 file3 file4 6 cat file 5 With the above history, what would be the... (5 Replies)
Discussion started by: Dbyte
5 Replies

Featured Tech Videos