...
I have a text file of data where I want to search for a particular string but return the prior line.
...
If you want to return just one prior line using Perl, then pludi's Perl script is extremely efficient.
Here's a variation though, but the underlying concept is the same - print variable p when string matches and then save the current line to variable p.
By the definition of your problem, it won't print anything if you match "LINE_1" in the file above.
And you'll never be able to print the last line either.
Quote:
... when I input an extremely wide file (like 50,000+ characters in 1 line), this is failing.
...
I created a dummy file very similar to f5 above, but with each line containing 1,000,000 characters (1 million). And the script worked fine. Even with the search string being at the very end of the 1-million character line.
Quote:
Can this be easily re-written into a Perl script?
I'll leave it for you to decide.
Quote:
And can Perl handle extremely wide files?
The idea here is to save the entire line in a single Perl variable ($p above or $prev in pludi's script). Perl imposes no limitation on the length of a string variable. It is limited only by your system's memory.
Collegues
I have an AWK script like the following.
{
if ($2 ~ /JJ/ && $4 ~ /IN/)
{
print $2, $3, $4, $5
}
}
How can I embed it in a perl program.
Jaganadh.G (5 Replies)
Hey all, Im trying to write a script on windows, which Im not too familiar with. Im generally a bash scripting guy but am using perl for this case.
My question is...
I have this exact output:
2 Dir(s) 6,380,429,312 bytes free
and I just need to get the number out... (4 Replies)
Hi Linux users,
I have to convert a shell script in a perl script!
The command takes two files (two tables) and compares them to find the same values in 4 columns ($2" "$3" "$8" "$9) and prints out only the common lines.
This is the command:
cat first_file.txt | while read i; do cat... (2 Replies)
I have a simple perl script that looks similar to this:
#!/usr/bin/perl/
# Have a lot of PERL code in the front of this script.
#Would now like to execute a system command using AWK
system (qq(cd /location && awk '/full/ {print $1;exit}' /myfile));
The system command in my perl script... (4 Replies)
Hi,
I have to make an script according to these:
- I have couples of files like:
xxxxxxxxxxxxx.csv
xxxxxxxxxxxxx_desc.xml
- every xml file has diferent fields, but keeps this format:
........
<defaultName>2011-02-25T16:43:43.582Z</defaultName>
........... (2 Replies)
i have two files as shown below
t1.txt:
argument1
argu2
argu37
t2.txt:
22
33
44
i want o/p as
argument1 22
argu2 33
argu37 44
i am trying to merge two file under perl script using following
system("paste t1.txt t2.txt | awk... (3 Replies)
Input file (a list of input file name with *.txt extension):
campus.com_icmp_ping_alive.txt
data_local_cd_httpd.txt
data_local_cd.txt
new_local_cd_mysql.txt
new_local_cd_nagios_content.txt
Desired output file:
data local_cd_httpd
data local_cd
new local_cd_mysql
new ... (9 Replies)
Hi gurus, I am trying to match records in following format:
(-,username,domain1.co.uk)\
(-,username,domain2.co.uk)
either awk or perl must be used. I am using cygwin. I wrote following code which works and matches both above entries:
awk 'BEGIN {musr="(-,username,+.co.uk)"} {if... (8 Replies)
Hello,
I am writing a Natural Language Parser and one of the tools I need is to separate prepositional phrase markers which begin with a Preposition. I have a long list of such markers (sample given below)and am looking for a script in awk or perl which will allow me to access a look-up file... (2 Replies)
Dear all,
I have a database of compound words. I want to retain only strings with a single hyphen and identify those strings which have more than one hyphen. I am giving an example below
test-test
test-test-test
test-test-test-test-test
good-for-nothing
The regex/script should remove all... (11 Replies)