Text strings in files.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text strings in files.
# 1  
Old 02-02-2010
Text strings in files.

Hi all

I have two files X.txt and Y.txt. The file format of X.txt is :

Code:
madras is also the fountainhead of the theosophical movement which spread worldwide .

and second file Y.txt is of the format:

Code:
madra|s|nsubj is|cop also|advmod the|det fountainhead|empty of|prep the|det theosophical|amod movement|prep_of which|nsubj spread|rcmod worldwide|dobj .|

In Y.txt file , there are some texts units separated by two "|" (i.e.,madra|s|nsubj ) and some texts are separated by one "|" (i.e., also|advmod).

Considering the two files , the expected output is :

Code:
madras|madra|s|nsubj is|is|empty|cop also|also|empty|advmod the|the|empty|det fountainhead|fountainhead|empty|empty of|of|empty|prep the|the|empty|det theosophical|theosophical|empty|amod movement|movement|empty|prep_of which|which|empty|nsubj spread|spread|empty|rcmod worldwide|worldwide|empty|dobj .|

In the final output file, all texts units separated by three "|" (i.e., madras|madra|s|nsubj).
To obtain the expected output file, for each texts unit separated by two "|" in Y.txt file, the first corresponding words is copied from X.txt and separated by "|" with the word from Y.txt file (i.e., madras|madra|s|nsubj) from the corresponding location of the corresponding sentence. And for each texts units separated by one "|" in Y.txt file, the corresponding word with "|empty" string is inserted in between the string separated by "|" (i.e., is|is|empty|cop)

I want to write a Perl script on this.
Thanks in advance.

Last edited by my_Perl; 02-03-2010 at 01:28 AM..
# 2  
Old 02-02-2010
Can you tell us what you have done?

I have given some answers on your another post, with similar request, maybe you can refer it first.
# 3  
Old 02-03-2010
I prefer a perl script for this if possible.
# 4  
Old 02-04-2010
Help Please.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

2. Shell Programming and Scripting

awk to get text between 2 strings

Hi, I am trying different scenarios now, 1 of those is getting the text between the following 2 strings. Type of msg: -in_full >date >alr text >ID_on_exit AWXX-Ready to commit (98) msg type: (10) I need to get all the occurrences having the same start line and end line.... (6 Replies)
Discussion started by: ocramas
6 Replies

3. Shell Programming and Scripting

Finding a text in files & replacing it with unique strings

Hallo Everyone. I have to admit I'm shell scripting illiterate . I need to find certain strings in several text files and replace each of the string by unique & corresponding text. I prepared a csv file with 3 columns: <filename>;<old_pattern>;<new_pattern> ... (5 Replies)
Discussion started by: gordom
5 Replies

4. Shell Programming and Scripting

Extract text between two strings

Hi I have something like this: EXAMPLE 1 CREATE UNIQUE INDEX "STRING_1"."STRING_2" ON "BOSNI_CAB_EVENTO" ("CD_EVENTO" , "CD_EJECUCION" ) PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 5242880 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "DB1000_INDICES_512K"... (4 Replies)
Discussion started by: chrispaz81
4 Replies

5. Shell Programming and Scripting

Help with Comparing 2 strings from text

Hey guys how do I compare 2 strings from the text file, and check for duplication? For example, I add an item call Laptop, it will record to the textfile call file. If it detects duplicate it will say the record record exist? file.txt contains Laptop:Sony:1000 Phone:Apple:30 A head... (4 Replies)
Discussion started by: aLHaNz
4 Replies

6. Shell Programming and Scripting

How to Extract text between two strings?

Hi, I want to extract some text between two strings in a line i am using following command i.e; awk '/-string1/,/-string2/' filename contents of file is--- line1 line2 aaa -bbb -ccc -string1 c,d,e -string2 line4 but it is showing complete line which is having searched strings. aaa... (19 Replies)
Discussion started by: emresearch
19 Replies

7. Shell Programming and Scripting

Extended replacing of nonspecific strings in text files [beware complicated !]

Well, to make another post at this helpful forum :b::D: I recently tried something like this, I want to replace all those numberings/letters that are located between <string>file://localhost/var/mobile/Applications/ and /Documents/</string> numberings =---- replace with: first... (6 Replies)
Discussion started by: pasc
6 Replies

8. Shell Programming and Scripting

Extracting text between two strings

Hi, I've looked at a few existing posts on this, but they don't seem to work for my inputs. I have a text file where I want to extract all the text between two strings, every time that occurs. Eg my input file is Anna said that she would fetch the bucket. Anna and Ben moved the bucket.... (9 Replies)
Discussion started by: JamesForeman
9 Replies

9. Shell Programming and Scripting

Compare text strings.

Hi Im trying to write a script that compare a text string. But it fails, I think it adds a extra line feed to the result and fails beacuse of that. The script. DT=`date +'%Y%m%d%H%M%S'` #ALARM_BIN=/users/alarms/ssa/alarms/bin QUEUE_THR=10 #unset offset #offset="***Server reports data... (3 Replies)
Discussion started by: vettec3
3 Replies

10. Shell Programming and Scripting

Deleting files that don't contain particular text strings / more than one instance of a string

Hi all, I have a directory containing many subdirectories each named like KOG#### where # represents any digit 0-9. There are several files in each KOG#### folder but the one I care about is named like KOG####_final.fasta. I am trying to write a script to copy all of the KOG####_final.fasta... (3 Replies)
Discussion started by: kmkocot
3 Replies
Login or Register to Ask a Question