Perl: Instering Names in to Text.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: Instering Names in to Text.
# 1  
Old 07-16-2009
Perl: Instering Names in to Text.

Hello my friends,

So I'm trying to insert some extra text in to text file/lines.

w• Test-LinesXtra: INS ABC 123456 123456
w• Test-LinesXtra: INS DEF 123456 123456
w• TestLinesXtra: 123456 123456
w• TestLinesXtra: 123456 123456

I would like to insert text in in place of "INS ABC" text will be static not changing
Each line will have different text to insert ...

Is there easy way to do it like ...

line 1; insert ABC after w• TestLinesXtra:
line 2; insert DEF after w• TestLinesXtra:

Beside I did small function in perl to find and replace .. it works but I can't replace bullets "•"

Last edited by NDxiak; 07-16-2009 at 07:16 PM..
# 2  
Old 07-17-2009
Quote:
Originally Posted by NDxiak
...

So I'm trying to insert some extra text in to text file/lines.

w• Test-LinesXtra: INS ABC 123456 123456
w• Test-LinesXtra: INS DEF 123456 123456
w• TestLinesXtra: 123456 123456
w• TestLinesXtra: 123456 123456

I would like to insert text in in place of "INS ABC" text will be static not changing
What do you want to replace "INS ABC" with ?

Quote:
Each line will have different text to insert ...
Again, what do you want to replace "INS ABC" with ?
What do you want to replace "INS DEF" with ?

Quote:
Is there easy way to do it like ...

line 1; insert ABC after w• TestLinesXtra:
line 2; insert DEF after w• TestLinesXtra:
Do you want to replace "INS ABC" with "ABC" ? i.e. do you want to just remove "INS " ?
Do you want to replace "INS DEF" with "DEF" ? i.e. do you want to just remove "INS " ?

Quote:
Beside I did small function in perl to find and replace .. it works but I can't replace bullets "•"
Yes, but replacing bullets was not your problem !
If you review your question again, you will find that you asked to insert some text after "w• TestLinesXtra:"

Quote:
Is there easy way to do it like ...

line 1; insert ABC after w• TestLinesXtra:
line 2; insert DEF after w• TestLinesXtra:
You never mentioned you wanted to replace the bullet itself.

You may want to phrase your question properly. Or at least show the file before and after the transformation you seek.

tyler_durden
# 3  
Old 07-17-2009
Hey,

Sorry for confusing you ...
I got bullet thing resolved so thank you anyways...

And replacing ...
Before:
w• Test-LinesXtra: 123456 123456
w• Test-LinesXtra: 123456 123456

After:

w• Test-LinesXtra: TEST1 123456 123456
w• Test-LinesXtra: TEST2 123456 123456

so after w• Test-LinesXtra: im adding TEST1 and TEST2 and this needs to be added before 123456

Thank You
# 4  
Old 07-18-2009
Quote:
Originally Posted by NDxiak
...
Before:
w• Test-LinesXtra: 123456 123456
w• Test-LinesXtra: 123456 123456

After:

w• Test-LinesXtra: TEST1 123456 123456
w• Test-LinesXtra: TEST2 123456 123456

so after w• Test-LinesXtra: im adding TEST1 and TEST2 and this needs to be added before 123456

...
Code:
$ 
$ cat data.txt
w• Test-LinesXtra: 123456 123456
w• Test-LinesXtra: 123456 123456
$ 
$ perl -pi -e 's/(Test-LinesXtra:)/$1 TEST$./' data.txt
$ 
$ cat data.txt
w• Test-LinesXtra: TEST1 123456 123456
w• Test-LinesXtra: TEST2 123456 123456
$ 
$

tyler_durden
# 5  
Old 07-20-2009
Thank You !

I have problem with running this script

Quote:
Bareword found where operator expected at fr.pl line 4, near "$ cat data"
(Missing operator before data?)
syntax error at fr.pl line 4, near "$ cat data"
Unrecognized character \xE2 at fr.pl line 5.
# 6  
Old 07-20-2009
Quote:
Originally Posted by NDxiak
Thank You !

I have problem with running this script
From your terminal, copy and paste your Unix session over here, so that it shows what exactly you executed and what error it displayed.

tyler_durden
# 7  
Old 07-20-2009
I guess that Im being stupid and I should include more stuff in this code ?
I tried to research those functions -pi -e but google its not helpful at all

command to execute if it matters "perl xs.pl"

Code:
#!/usr/bin/perl
open FILE, "data.txt" or die $!;
$ 
$ cat data.txt
w• Test-LinesXtra: 123456 123456
w• Test-LinesXtra: 123456 123456
$ 
$ perl -pi -e 's/(Test-LinesXtra:)/$1 TEST$./' data.txt
$ 
$ cat data.txt
w• Test-LinesXtra: TEST1 123456 123456
w• Test-LinesXtra: TEST2 123456 123456
$ 
$

Thank You In Advance

Last edited by NDxiak; 07-20-2009 at 04:55 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inserting text in file names while copying them.

I'm trying to find a Bourne shell script that will copy files from one directory using a wild card for the file name (*) and add some more characters in the middle of the file name as it is copied. As an example: /u01/tmp-file1.xml => /u02/tmp-file1-20130620.xml /u01/tmp-file2.xml => ... (6 Replies)
Discussion started by: Tony Keller
6 Replies

2. Shell Programming and Scripting

Removing files with same text but different file names

Hi All, I have some 50,000 HTML files in a directory. The problem is; some HTML files are duplicate versions that is wget crawled them two times and gave them file names by appending 1, 2, 3 etc after each crawl. For example, if the file index.html has been crawled several times, it has been... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

3. Shell Programming and Scripting

Opening File names with spaces inside it !- PERL

I developed a perl code..And the excerpt from it is given below... open(HANDLE,$cmp_path) ; #reading the xml file from the file path while($file_path = <HANDLE>) I have list of XML files to read from a folder. It has some spaces inside the name of the file...I used "\"... (2 Replies)
Discussion started by: gameboy87
2 Replies

4. Shell Programming and Scripting

Replace variable names in text file with its value

Hi I have a text file (mytext.txt), the content of which is as following: My name is <@MY_NAME@> and my age is <@MY_AGE@> . Now i have another property file (myprops) which is as following: MY_NAME=abcdefgh MY_AGE=000000 I was wondering, how can i replace the tags of mytext.txt, with its... (1 Reply)
Discussion started by: vigithvg
1 Replies

5. Shell Programming and Scripting

matching names in 2 text files

I have 2 text files like ________________________________ Company Name:yada yada ADDRESS:some where, CITY,STATE CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3 LEAD:first_name.last_name ________________________________ & Data file2 ... (1 Reply)
Discussion started by: rider29
1 Replies

6. Shell Programming and Scripting

extracting domain names out of a text file

I am needing to extract and list domain names out of a very large text file. The text file contains tlds .com .net .org and others as well as third level domains e.g. host1.domain.com and the names are placed within paragraphs of text. Domains do not have a http:// prefix so I'm thinking the... (6 Replies)
Discussion started by: totus
6 Replies

7. UNIX for Dummies Questions & Answers

Comparing file names to text document

Hi All, I'm really new to Unix scripts and commands but i think i'm eventually getting the hang of some of it. I have a task which is to create some kind of script which compares the file names in a directory, with the associated file name in a .txt file. We send out some data and Unix has a... (1 Reply)
Discussion started by: gman
1 Replies

8. Shell Programming and Scripting

Show column names when access a table using perl

Hi all, I am using the following code in order to access the data of a table: my $sql = qq{ SELECT * FROM cc_test_cases}; $sth = $dbh->prepare( $sql ); $sth->execute( ); while(@row1 = $sth->fetchrow_array()) { # print "$row1: $row1\n"; print "@row1\n"; #print("THE VALUE... (1 Reply)
Discussion started by: chriss_58
1 Replies

9. Shell Programming and Scripting

processing file names using text files

Hi, I have to perform an iterative function on a set of 10 files. After the first round the output files are named differently than the input files. examples input file name = xxxx1.yyy output file name = xxxx1_0001.yyy I need to rename all of the output files to the original input... (5 Replies)
Discussion started by: ligander
5 Replies

10. Shell Programming and Scripting

How to set dynamically keys names in perl %hash

hello I have loop , in this loop im picking names , this names I want to be keys in %hash but I don't know how to set in every loop entertain different key in the %hash (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question