Sponsored Content
Top Forums Shell Programming and Scripting Select last block from a file Post 302092613 by shreedhar on Wednesday 11th of October 2006 05:32:30 AM
Old 10-11-2006
#! /usr/bin/perl

$file='last_block'; #file name
open (FH, $file);

while ($line=<FH>) {
undef(@array);
chomp($line);
if($line =~ /^START/) {
while ($temp = <FH>) {
chomp($temp);
if ($temp =~ /^END/) {
last;
}
push(@array, $temp);
}
@copy=@array;
}
}
print "@copy\n";

input file (last_block):
START
i am in first block
Now tell me i am...
END


START
i am in second block
now tell me i am
...
END

START
I am last block
did u asked me
END

output:
I am last block did u asked me
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

select a record from one file matching from second file using awk

I need help :) I have two input files and I'd like to generate a report based on the two. filea: hostname,account1,password ,account2,password hostname,account1,password hostname,account1,password ,account1,password ,account2,password repeating hostnames are blank fileb: hosta... (7 Replies)
Discussion started by: synmag
7 Replies

2. Shell Programming and Scripting

Select block of text around matching braces

Hi, I have several block of text that I need to select, however this text may be spread over several lines and contains the '{' and '}' within it. For e.g., ABC=100{ DEF = 200 { GHI, JKL } } #2nd Block 123 { 456{78,910}} }I am trying to figure out how to remove... (2 Replies)
Discussion started by: BootComp
2 Replies

3. Shell Programming and Scripting

Select a pattern from file

Hi, I have a requirement to select only a specific pattern from a flat file and delete its occurance. For eg. If my file contains : <A1>1234</A1> <A2>5678</A2> <ABC>1234</ABC> <A3>0987</A3> Then, i want to delete <ABC>1234</ABC> from the file and have the contents as :-... (7 Replies)
Discussion started by: DTechBuddy
7 Replies

4. Shell Programming and Scripting

Select some lines from a txt file and create a new file with awk

Hi there, I have a text file with several colums separated by "|;#" I need to search the file extracting all columns starting with the value of "1" or "2" saving in a separate file just the first 7 columns of each row maching the criteria, with replacement of the saparators in the nearly created... (4 Replies)
Discussion started by: capnino
4 Replies

5. UNIX for Dummies Questions & Answers

select first column of file

Hi, Following is my file output 247 Sleep 25439 NULL 259 Sleep 25460 NULL 277 Sleep 15274 NULL 361 Sleep 2 NULL 362 Sleep 202 NULL I want to select only first column to other file How can... (2 Replies)
Discussion started by: kaushik02018
2 Replies

6. Shell Programming and Scripting

Select older file if multiple file exists with same name

Hi I want to select older file if multiple files exist with same name. eg:There are five files in UNIX folder Sample1_20091231 Sample1_20100110 Sample1_20100115 Sample2_20100115 Sample3_20100115 However in file list i.e FileName.DAT I have data like Sample1 Sample2 Sample3 I am... (5 Replies)
Discussion started by: dashing201
5 Replies

7. Shell Programming and Scripting

Block of records to select from a file

Hello: I am new to shell script programming. Now I would like to select specific records block from a file. For example, current file "xyz.txt" is containing 1million records and want to select the block of records from line number 50000 to 100000 and save into a file. Can anyone suggest me how... (3 Replies)
Discussion started by: nvkuriseti
3 Replies

8. Shell Programming and Scripting

Select data from a file

Hi , I want to select data from a file .the datas in a file will be in both upper and lower case. can able to select particular data using awk. file is like Ram Selva 24332 UNIXTEAM Karthi Siva 43322 UNIXTEAM In read if i enter selva as lowercase its not displaying result. (9 Replies)
Discussion started by: boopal
9 Replies

9. Shell Programming and Scripting

Short program to select lines from a file based on a second file

Hello, I use UBUNTU 12.04. I want to write a short program using awk to select some lines in a file based on a second file. My first file has this format with about 400,000 lines and 47 fields: SNP1 1 12.1 SNP2 1 13.2 SNP3 1 45.2 SNP4 1 23.4 My second file has this format: SNP2 SNP3... (1 Reply)
Discussion started by: Homa
1 Replies

10. Shell Programming and Scripting

Select table name from file

i have a file tabel.out which contain table name in this format. xyz abc qwe Plz help me writing one script which actually takes tablename from file table.out file one by one and then select count (*) from $tablename limit 10; and print error in output file if any tabel is not... (4 Replies)
Discussion started by: netdbaind
4 Replies
PPPOE-START(8)						      System Manager's Manual						    PPPOE-START(8)

NAME
pppoe-start - Shell script to bring up a PPPoE link SYNOPSIS
pppoe-start [config_file] pppoe-start interface user [config_file] DESCRIPTION
pppoe-start is a shell script which starts the Roaring Penguin user-space PPPoE client. If you omit config_file, the default file /etc/ppp/pppoe.conf is used. If you supply interface and user, then they override the Ethernet interface and user-name settings in the configuration file. AUTHOR
pppoe-start was written by David F. Skoll <dfs@roaringpenguin.com>. The pppoe home page is http://www.roaringpenguin.com/pppoe/. SEE ALSO
pppoe(8), pppoe-stop(8), pppoe-connect(8), pppd(8), pppoe.conf(5), pppoe-setup(8), pppoe-status(8), pppoe-sniff(8), pppoe-relay(8), pppoe- server(8) 4th Berkeley Distribution 21 February 2000 PPPOE-START(8)
All times are GMT -4. The time now is 02:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy