Sponsored Content
Top Forums Shell Programming and Scripting Split a text file into multiple pages based on pattern Post 302908832 by MadeInGermany on Thursday 10th of July 2014 04:16:48 PM
Old 07-10-2014
The criteria for a new file is the string JURISDICTION NUMBER:
No problem if this is the first line in the new file.
But you want already the previous line to go to the new file.
Here is a general solution with a backlog (ring-)buffer.
Code:
awk '
BEGIN {
  # backlog buffer length
  b=1
  # backlog buffer will be B[0]...B[b-1]
  # NR is the current line number
  # NR%b cycles thru 0...(b-1)
}
($1=="JURISDICTION" && $2=="NUMBER:") {
 # new output file
 ofile="Report-"$3".txt"
}
(NR>b) {
 # print the last line of the backlog buffer, but not for line 1...(b-1)
 print B[NR%b] > ofile
}
{
  B[NR%b]=$0
}
END {
  # print the outstanding lines from the backlog buffer
  for (i=1; i<=b; i++) print B[(NR+i)%b] > ofile
}
' Report-02.txt


Last edited by MadeInGermany; 07-11-2014 at 08:14 AM.. Reason: changed b=2 to b=1 and adapted code
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Split text file by pages

Hello! Firts of all, I'm sorry for my English. My problem: I have text file with few Form Feed symbols (FF, ASCII code =12) inside (for example - some report, consists of some pages for printing). I want to split this text by pages - each page (until FF symbol) in single file. I... (2 Replies)
Discussion started by: ranri
2 Replies

2. Shell Programming and Scripting

Split a file based on a pattern

Dear all, I have a large file which is composed of 8000 frames, what i would like to do is split the file into 8000 single files names file.pdb.1, file.pdb.2 etc etc each frame in the large file is seperated by a "ENDMDL" flag so my thinking is to use this flag a a point to split the files... (4 Replies)
Discussion started by: Mish_99
4 Replies

3. Shell Programming and Scripting

Split a file into multiple files based on the input pattern

I have a file with lines something like. ...... 123_start ...... ....... 123_end .... ..... 456_start ...... ..... 456_end .... ..... 789_start .... .... 789_end (6 Replies)
Discussion started by: abinash
6 Replies

4. UNIX for Dummies Questions & Answers

print multiple lines from text file based on pattern list

I have a text file with a list of items/patterns: ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig12238 ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig34624... (1 Reply)
Discussion started by: Oyster
1 Replies

5. Shell Programming and Scripting

split XML file into multiple files based on pattern

Hello, I am using awk to split a file into multiple files using command: nawk '{ if ( $1 == "<process" ) { n=split($2, arr, "\""); file=arr } print > file }' processes.xml <process name="Process1.process"> ... (3 Replies)
Discussion started by: chiru_h
3 Replies

6. Shell Programming and Scripting

Split a file based on pattern and size

Hello, I have a large file (2GB) that I would like to split based on pattern and size. I've used the following command to split the file (token is "HELLO") awk '/HELLO/{i++}{print > "file"i}' input.txt and the output is similar to the following (i included filesize in KB): 10 ... (2 Replies)
Discussion started by: jl487
2 Replies

7. Shell Programming and Scripting

Split the file based on pattern

Hi , I have huge files around 400 mb, which has clob data and have diffeent scenarios: I am trying to pass scenario number as parameter and and get required modified file based on the scenario number and criteria. Scenario 1: file name : scenario_1.txt ... (2 Replies)
Discussion started by: sol_nov
2 Replies

8. UNIX for Dummies Questions & Answers

Split a huge 7 GB File Based on Pattern into 4 files

Hi, I have a Huge 7 GB file which has around 1 million records, i want to split this file into 4 files to contain around 250k messages each. Please help me as Split command cannot work here as it might miss tags.. Format of the file is as below <!--###### ###### START-->... (6 Replies)
Discussion started by: KishM
6 Replies

9. UNIX for Advanced & Expert Users

Split one file to many based on pattern

Hello All, I have records in a file in a pattern A,B,B,B,B,K,A,B,B,K Is there any command or simple logic I can pull out records into multiple files based on A record? I want output as File1: A,B,B,B,B,K File2: A,B,B,K (9 Replies)
Discussion started by: deal1dealer
9 Replies

10. UNIX for Beginners Questions & Answers

UNIX script to append multiple text files into one file based on pattern present in filaname

Hi All-I am new to Unix , I need to write a script. Can someone help me with a requirement where I have list of files in a directory, I want to Merge the files if a pattern of string matches in filenames? AAAL_555A_ORANGE1_F190404.TXT AAAL_555A_ORANGE2_F190404.TXT AAAL_555A_ORANGE3_F190404.TXT... (6 Replies)
Discussion started by: Shankar455
6 Replies
SOCKET_LISTEN(3)							 1							  SOCKET_LISTEN(3)

socket_listen - Listens for a connection on a socket

SYNOPSIS
bool socket_listen (resource $socket, [int $backlog]) DESCRIPTION
After the socket $socket has been created using socket_create(3) and bound to a name with socket_bind(3), it may be told to listen for incoming connections on $socket. socket_listen(3) is applicable only to sockets of type SOCK_STREAM or SOCK_SEQPACKET. PARAMETERS
o $socket - A valid socket resource created with socket_create(3). o $backlog - A maximum of $backlog incoming connections will be queued for processing. If a connection request arrives with the queue full the client may receive an error with an indication of ECONNREFUSED, or, if the underlying protocol supports retransmission, the request may be ignored so that retries may succeed. Note The maximum number passed to the $backlog parameter highly depends on the underlying platform. On Linux, it is silently truncated to SOMAXCONN. On win32, if passed SOMAXCONN, the underlying service provider responsible for the socket will set the backlog to a maximum reasonable value. There is no standard provision to find out the actual backlog value on this plat- form. RETURN VALUES
Returns TRUE on success or FALSE on failure. The error code can be retrieved with socket_last_error(3). This code may be passed to socket_strerror(3) to get a textual explanation of the error. SEE ALSO
socket_accept(3), socket_bind(3), socket_connect(3), socket_create(3), socket_strerror(3). PHP Documentation Group SOCKET_LISTEN(3)
All times are GMT -4. The time now is 05:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy