hi,
i have a question about replacing text after a defined string.
for example :
the text goes.
##|######|##### ##_##| ########...
##|######|##### ##_##|########. ..
...
i'm trying to replace the text after the last '|' simbol with the expresion:
s/$'/$a/;
but it doesn't work in fact the :
s/$` /$a/
works but only when there is space between the | and next word.
also if i try to do this : s/$`/$a/ it replaces my expression with the $a .like this:
$a|########...
if i wasn't clear enough my goal is to have this in the end:
##|######|##### ##_##|$a
thank you!
3 1679 numberwhun 3,509
Recognized Expert Moderator Specialist
Well, my question to you would be, are there always going to be 4 fields, separated by a "|"? If there are, then you could do the following: -
use strict;
-
use warnings;
-
-
open(FILE, "<Text1.txt");
-
-
while(<FILE>)
-
{
-
chomp($_);
-
my @line = split(/\|/, $_);
-
-
$line[3] = $a;
-
}
-
If not, then you can use the "$#line" syntax to determine the last array index and then set it from there.
Regards,
Jeff
well, it will always be 4 fields at least, but there could be even few 100 or even 1000 fields with quite a lot of data in one field. but i need only first 3 and the rest i want to replace with a defined variable.
those are txt files and quite large from 2 GB up.
i was considering to transform it to array but i think that would drastically slow down the process (or not?).
thanks,
robert
numberwhun 3,509
Recognized Expert Moderator Specialist
I am going to assume that you mean that there could be 100's or even 1000's of "lines" in the file, not fields.
That should not be a problem. The code above will take and process each line individually. All you would need to do after reading each line, is have it outputted to a new file if that is what you wanted to do.
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dave Stone |
last post by:
Does anyone know if it's possible to use the wizard or DTS Designer to
accept a source file with the following simplified format:
<field1label>: <record1field1value>
<field2label>: <record1field2value>
- - - - - - -
<fieldNlabel>: <record1fieldNvalue>
<field1label>: <record2field1value>
<field2label>: <record2field2value>
|
by: Mike Husler |
last post by:
We tried to load a file that contained 1 column of datetimes of the format
yyyy-MM-dd hh:mm:ss into a table that had the column set as a datetime type.
We did this using a DTS package. The error from DTS is attached. There seems
to be strange characters hidden in the file because a visual scan of all the data yielded
that they were all of valid datetime format. The files were transfered from a UNIX machine
to Windows via FTP. The file...
|
by: expect |
last post by:
What's the big deal with importing text files? I have a 70 MB file to import
and it's been one problem after another. I used the copy command and it appears
that it's just not possible. I finally massaged the file into a .sql file and
ran that using \i db.sql but that failed too because I overlooked ' in names
like D'Adario. The other problem I encountered was that a numeric field had
to have data in it, pg would not default to the...
|
by: suzy |
last post by:
hello,
i want to search a text file for an occurrence of a string and replace some
text after the match, then save the file.
eg: if the file is:
<start>
Hello my name is tony, I am 22.
Hello, my name is sonia, I am 18.
|
by: VMI |
last post by:
In Access, when a user's going to import a fixed-width format ascii file, a
window in the "Import Text Wizard" lets the user "mark" where in a string
one field will begin and end (with the vertical lines that can be moved with
the mouse). Can this (or something similar) be implemented in order for the
user to graphically choose which part of the string will be, for example, be
displayed in a MessageBox?
So for example, my control would...
| |
by: Brad Sanders |
last post by:
Hello All,
Thanks to Richard's answer to my last post I understand
now what I have to do, but..
How do I put a Line Feed or a Form Feed into a text file?
Looking throught the .net help it mentions \f but
illustrates no way write it to a text file.
Thanks
|
by: Alexis Gallagher |
last post by:
(I tried to post this yesterday but I think my ISP ate it. Apologies if
this is a double-post.)
Is it possible to do very fast string processing in python? My
bioinformatics application needs to scan very large ASCII files (80GB+),
compare adjacent lines, and conditionally do some further processing. I
believe the disk i/o is the main bottleneck so for now that's what I'm
optimizing. What I have now is roughly as follows (on python...
|
by: kevin |
last post by:
I need to parse an third party supplied delimited or fixed width text file
into a datatable. The delimiter may vary.
I am currently using a SteamReader to read each line and, for delimited
files, String.Split() to break each line into an array based on the
delimiter. The problem, as you may guess, is that the delimiter character is
being used in the data
i.e. "Kevin","Williams,"I like commas, I really do"
|
by: Ahmed, Shakir |
last post by:
I need to remove text string from the list of the numbers mentioned
below:
080829-7_A
070529-5_c
080824-7_O
070405_6_p
The output will be : 080829-7
070529-5
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |