How to concatenate texts in perl only?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to concatenate texts in perl only?
Prev   Next
# 1  
Old 09-16-2011
How to concatenate texts in perl only?

Hi,

I want to concatenate the texts in the file but there are different scenario's.
Code:
Ist Scenario.
The contents of file has id`language,sequence number,text,language
Here id`language is a key pair to identify the correct language.
Sequnce number is the order the text being inserted.
Text is the description.
language is the actual language i.e. english, japanese ....
seperater is @|

Code:
#file.txt
12345`English@|1@|perl is a scripting language@|English
12345`English@|2@|Regular expression support is vast@|English
12345`English@|3@|Has various items@|English
12345`English@|4@|xml support is good@|English

The texts should be concatenated in the order of sequence numbers.
The final output should not contain sequence numbers.
Output:
Code:
12345`English@|perl is a scripting language Regular expression support is vast Has various items xml support is good@|English


2nd Scenario.
#Contents of file1.txt have:
Code:
id`language,sequence number,desc code,desc number,ent id,text,language 
12345`English@|1@|DC@|34@|4456@|Text needs to be concatenated@|English
12345`English@|2@|FC@|36@|4455@|Text needs to be concatenated-1@|English
12345`English@|3@|BC@|39@|4453@|Text needs to be concatenated-2@|English

Output:
Code:
12345`English@|DC@|34@|4456@|FC@|36@|4455@|BC@|39@|4453@|Text needs to be concatenated Text needs to be concatenated-1 Text needs to be concatenated-2@|English

3rd Scenario.
#Contents of file1.txt have:
Code:
id`pid`language,sequence number,text,language code,language
12345`34445`English@|1@|desc text-1@|1000@|English
12345`34445`English@|2@|desc text-2@|1000@|English

Output:
Code:
2345`34445`English@|desc text-1 desc text-2@|1000@|English

4th Scenario.
#Contents of file1.txt have:
id`pid`language,sequence number,text,dsc code,desc inf,dsc flag,language code,language
The dsc code,desc inf,dsc flag may be or may not be same
Code:
12345`34445`Japanese@|1@|text-1@|WE@|PRT@|F@|500@|Japanese
12345`34445`Japanese@|2@|text-2@|WE@|PRT@|F@|500@|Japanese

Output:
Code:
12345`34445`Japanese@|WE@|PRT@|F@|text-1 text-2@|500@|Japanese

If the text is empty no concatenation of texts should happen.

How can i do it in perl?

Any suggestions.

Regards
Vanitham
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Aligning Texts

is there any way to align my text so every column begins on the same line as the previous line? here's my command: printf "THEN ( ${SEARCHPATTB} = Hour = ${CALTOTB} ) %8s => %8s NOW ( ${SEARCHPATT} = Hour = ${CALTOT} ) %7s => %7s Reduced By: %7s -${RESULT}"\\n output i'm currently getting... (2 Replies)
Discussion started by: SkySmart
2 Replies

2. Post Here to Contact Site Administrators and Moderators

Can there be alt-texts to icons?

Can you add hover texts (alt-texts) to icons? It is not always obvious what each of them mean just by looking at them. Sometimes it is clear from the url it points to, but for accessibility reasons alone it would be good to have alt-texts as a standard. (1 Reply)
Discussion started by: figaro
1 Replies

3. Shell Programming and Scripting

Concatenate small line with next line perl script

Hello to all, I'm new to perl, I have input file that contains the string below: 315350535ff450000014534130101ff4500ff45453779ff450ff45545f01ff45ff453245341ff4500000545000This string has as line separator "ff45". So, I want to print each line but the code below is not working. perl -pe '... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

4. UNIX for Dummies Questions & Answers

Texts between 2 strings

Hi, I have a file with texts shown below, <2013 abc <2013 start request pdu dot1q end pdu response pdu dot1q end pdu am searching for the text "dot1q" , when it matches in the file , i need the contents between "<2013 start" and "end pdu". Can some one help on this ? ... (5 Replies)
Discussion started by: giri_luck
5 Replies

5. UNIX for Dummies Questions & Answers

perl filter unique and concatenate

Hi experts, I have some input like below, TEST A function W TEST A function X TEST B function Y TEST C function Z TEST C function ZY i would like to have below output, TEST A function W&X TEST B function Y TEST C function Z&ZY Please kindly help on this, i am cracking my head... (2 Replies)
Discussion started by: mingfatty
2 Replies

6. Shell Programming and Scripting

Perl concatenate an array

Not a perl guru and need some help with a script I inherited. My perl script has a variable that is concatenated and works fine as is, but what I need is to remove a string in the output and input a files content. This is emailed as a html report and I can't get the file to output in the email... (5 Replies)
Discussion started by: numele
5 Replies

7. Shell Programming and Scripting

extract texts using awk

Hello, I have two files: File1: a b c d File2: b c e I need 'e' as output.... Thanks.. ---------- Post updated at 12:16 PM ---------- Previous update was at 12:15 PM ---------- (1 Reply)
Discussion started by: shekhar2010us
1 Replies

8. Shell Programming and Scripting

Two Huge Texts and Combine Result to Third

hi, i want to examine two file and write some codes to a third file. note that seperators are TAB, not space. first file: 192.168.1.1 3 192.168.1.2 2 192.168.3.2 2 192.168.7.3 1 ... second file: 192.168.1.1 1 10.15.1.1 3 30 10.15.2.1 2 40 192.168.1.1 2 10.23.4.5... (3 Replies)
Discussion started by: gc_sw
3 Replies

9. Shell Programming and Scripting

Concatenate Logs - Perl Question

Hi All, I am fresh to perl and had been using shell scripting in my past experiences. In my part of perl program, i am trying to run a application command ccm stop, which should give some string output as the result. The output (error or sucess) has to be returned to an exisiting log file.... (4 Replies)
Discussion started by: ganga.dharan
4 Replies
Login or Register to Ask a Question