Sponsored Content
Top Forums Shell Programming and Scripting Perl how to move pointer to previous line in a txt file? Post 302161705 by KevinADC on Friday 25th of January 2008 02:13:59 PM
Old 01-25-2008
Yes, I think we both understood that requirement, and both suggestions can be used to do what you want. If you are familiar with looping through perl arrays using subscripts: $array[n] then using Tie::File will be pretty straight forward once you read the documentation.

S_M's suggestion reads the file in chunks, not line by line, and looks like it should work although the last match might fail if there isn't two newlines at the end of the file. You will have to try it and see or maybe he can clear that up.
 

10 More Discussions You Might Find Interesting

1. Programming

how to move file pointer to a particular line in c

Hello experts, I ve a text file I want to go to particular line . what is the best way to do this in c ? I am tried as follows fseek ( fh, pos, SEEK_SET); but this functions moves the file pointer according to a number of bytes. Unfortunately I don't know the exact byte... (7 Replies)
Discussion started by: user_prady
7 Replies

2. Shell Programming and Scripting

Move files one at the time and wait until the previous file is handled

I'm a novice at unix and need it more and more to do my work. I seem running into problems getting this script "attempt" to work: I need to copy all files in a directory, which is containing 22000 files, into a directory one level up. There a tool monitors the content of the dir and processes... (2 Replies)
Discussion started by: compasscard
2 Replies

3. Shell Programming and Scripting

[PERL] Cannot stat or move filename - £££F3AERO££.txt

Scenario: Users drop files into a directory which is regularly polled by my PERL process. On detecting a file my process will move it from the poll dir to a working directory. A user created a file with a £ symbol in the filename and my process now fails. e.g £££F3AERO££.txt ... (1 Reply)
Discussion started by: thefal9
1 Replies

4. Shell Programming and Scripting

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (1 Reply)
Discussion started by: johannd
1 Replies

5. UNIX for Dummies Questions & Answers

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (7 Replies)
Discussion started by: johannd
7 Replies

6. Shell Programming and Scripting

sed: how to move matched pattern to end of previous line

Hello, I'm new to this forum. I've been doing a lot of sed work lately and have found many useful tips on this forum. I've hit a roadblock in a project, though, and could really use some help. I have a text file with many lines like the following, i.e., some lines begin with a single word... (3 Replies)
Discussion started by: paroikoi
3 Replies

7. Shell Programming and Scripting

Perl: Conditional replace based on previous and current value in a line

I need to read the contents of a file. Then I need to grep for a keyword and replace part of the grepped line based on the condition of previous and present line. Example input file: V { port1 = P; port2 = 0; shift_port = P0; /* if next shift_port is P0 I need... (9 Replies)
Discussion started by: naveen@
9 Replies

8. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

9. UNIX for Dummies Questions & Answers

Split Every Line In Txt Into Separate Txt File, Named Same As The Line

Hi All Is there a way to export every line into new txt file where by the title of each txt output are same as the line ? I have this txt files containing names: Kandra Vanhooser Rhona Menefee Reynaldo Hutt Houston Rafferty Charmaine Lord Albertine Poucher Juana Maes Mitch Lobel... (2 Replies)
Discussion started by: Nexeu
2 Replies

10. UNIX for Beginners Questions & Answers

Move a TXT file greater or equal 355 MB with its corresponding .LST file

Good morning, i need your help please I need to move a .TXT file greater or igual 355 MB and its correspondent .LST file in a non recursive way The operating system is: uname -a SunOS server01c 5.10 Generic_144488-01 sun4u sparc SUNW,SPARC-Enterprise For example: rw-r--r-- 1 xptol ... (8 Replies)
Discussion started by: alexcol
8 Replies
Tie::Array(3pm) 					 Perl Programmers Reference Guide					   Tie::Array(3pm)

NAME
Tie::Array - base class for tied arrays SYNOPSIS
package Tie::NewArray; use Tie::Array; @ISA = ('Tie::Array'); # mandatory methods sub TIEARRAY { ... } sub FETCH { ... } sub FETCHSIZE { ... } sub STORE { ... } # mandatory if elements writeable sub STORESIZE { ... } # mandatory if elements can be added/deleted sub EXISTS { ... } # mandatory if exists() expected to work sub DELETE { ... } # mandatory if delete() expected to work # optional methods - for efficiency sub CLEAR { ... } sub PUSH { ... } sub POP { ... } sub SHIFT { ... } sub UNSHIFT { ... } sub SPLICE { ... } sub EXTEND { ... } sub DESTROY { ... } package Tie::NewStdArray; use Tie::Array; @ISA = ('Tie::StdArray'); # all methods provided by default package main; $object = tie @somearray,'Tie::NewArray'; $object = tie @somearray,'Tie::StdArray'; $object = tie @somearray,'Tie::NewStdArray'; DESCRIPTION
This module provides methods for array-tying classes. See perltie for a list of the functions required in order to tie an array to a package. The basic Tie::Array package provides stub "DESTROY", and "EXTEND" methods that do nothing, stub "DELETE" and "EXISTS" methods that croak() if the delete() or exists() builtins are ever called on the tied array, and implementations of "PUSH", "POP", "SHIFT", "UNSHIFT", "SPLICE" and "CLEAR" in terms of basic "FETCH", "STORE", "FETCHSIZE", "STORESIZE". The Tie::StdArray package provides efficient methods required for tied arrays which are implemented as blessed references to an "inner" perl array. It inherits from Tie::Array, and should cause tied arrays to behave exactly like standard arrays, allowing for selective overloading of methods. For developers wishing to write their own tied arrays, the required methods are briefly defined below. See the perltie section for more detailed descriptive, as well as example code: TIEARRAY classname, LIST The class method is invoked by the command "tie @array, classname". Associates an array instance with the specified class. "LIST" would represent additional arguments (along the lines of AnyDBM_File and compatriots) needed to complete the association. The method should return an object of a class which provides the methods below. STORE this, index, value Store datum value into index for the tied array associated with object this. If this makes the array larger then class's mapping of "undef" should be returned for new positions. FETCH this, index Retrieve the datum in index for the tied array associated with object this. FETCHSIZE this Returns the total number of items in the tied array associated with object this. (Equivalent to "scalar(@array)"). STORESIZE this, count Sets the total number of items in the tied array associated with object this to be count. If this makes the array larger then class's mapping of "undef" should be returned for new positions. If the array becomes smaller then entries beyond count should be deleted. EXTEND this, count Informative call that array is likely to grow to have count entries. Can be used to optimize allocation. This method need do nothing. EXISTS this, key Verify that the element at index key exists in the tied array this. The Tie::Array implementation is a stub that simply croaks. DELETE this, key Delete the element at index key from the tied array this. The Tie::Array implementation is a stub that simply croaks. CLEAR this Clear (remove, delete, ...) all values from the tied array associated with object this. DESTROY this Normal object destructor method. PUSH this, LIST Append elements of LIST to the array. POP this Remove last element of the array and return it. SHIFT this Remove the first element of the array (shifting other elements down) and return it. UNSHIFT this, LIST Insert LIST elements at the beginning of the array, moving existing elements up to make room. SPLICE this, offset, length, LIST Perform the equivalent of "splice" on the array. offset is optional and defaults to zero, negative values count back from the end of the array. length is optional and defaults to rest of the array. LIST may be empty. Returns a list of the original length elements at offset. CAVEATS
There is no support at present for tied @ISA. There is a potential conflict between magic entries needed to notice setting of @ISA, and those needed to implement 'tie'. AUTHOR
Nick Ing-Simmons <nik@tiuk.ti.com> perl v5.16.2 2012-10-11 Tie::Array(3pm)
All times are GMT -4. The time now is 08:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy