Sponsored Content
Top Forums Shell Programming and Scripting Split a content in a file with specific interval base on the delimited values using UNIX command Post 303004295 by apmcd47 on Friday 29th of September 2017 04:54:03 AM
Old 09-29-2017
Quote:
Originally Posted by rdrtx1
Code:
rm -f outfile_*

file_count=1
line_count=1

outfile="outfile_$file_count"

while read line
do
   echo "$line" >> $outfile
   (( line_count = line_count + 1 ))
   [[ $line_count -ge 5 ]] && { echo "$line" | grep -q "^ *; *$" && {
         (( file_count = file_count + 1 ))
         (( line_count = 1 ))
      }
      outfile="outfile_$file_count"
   }
done < input_file

This looks like it should work to me. Have you tested it? I don't think you need the echo "$line" | grep. If using ksh93 or bash 4 you could write:
Code:
[[ "${line}" =~ ";" ]] && [[ "${line_count}" -ge 5 ]] && {

Andrew
This User Gave Thanks to apmcd47 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to split pipe delimited file

I have a pipe delimited input file as below. First byte of the each line indicate the record type. Then i need to split the file based on record_type = null,0,1,2,6 and create 5 files. How do i do this in a ksh script? Pls help |sl||SL|SL|SL|1996/04/03|1988/09/15|C|A|sl||||*|... (4 Replies)
Discussion started by: njgirl
4 Replies

2. Shell Programming and Scripting

Retrieving values from tab-delimited file in unix script

Hi I am trying to retrieve values from a tab-delimited file.I am using while read record value=`echo $record | cut -f12` done Where 12 is the column no i want retieve and record is one line of the file. But it is returning the full record. Plz help (4 Replies)
Discussion started by: akashtcs
4 Replies

3. UNIX for Dummies Questions & Answers

unix command to insert double quotes in a delimited file

Hi, I am looking for a unix command which inserts double quotes around all values in a delimited file. For example, Input File 153665031,abc,abc ,abc 131278839,def,def ,dec 179821481,efg,efg ,lmn ... (6 Replies)
Discussion started by: Bachu
6 Replies

4. Shell Programming and Scripting

Extract value from delimited file base on white list

I would like to use a variable to store the IDs that I would like to extract. I would like to extract a list of values of the IDs from a delimited string. Using bash here. file format would be id1=we1;id2=er2;id3=rt3;id4=yu4 The number of fields and records is not fixed. There could be... (2 Replies)
Discussion started by: milo7
2 Replies

5. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

6. Shell Programming and Scripting

split file content into specific folders

Hi I have a large text file and I want to split its content into multiple flies. this large file contains several blocks of codes separated by a comment line for each block. this comment line represents a directory path So, when separate these blocks each into a separate file, This output... (7 Replies)
Discussion started by: turki_00
7 Replies

7. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

8. Linux

Split a large textfile (one file) into multiple file to base on ^L

Hi, Anyone can help, I have a large textfile (one file), and I need to split into multiple file to break each file into ^L. My textfile ========== abc company abc address abc contact ^L my company my address my contact my skills ^L your company your address ========== (3 Replies)
Discussion started by: fspalero
3 Replies

9. Shell Programming and Scripting

Split Big XML file Base on tag

HI I want to split file base on tag name. I have few header and footer on file <?xml version="1.33" encing="UTF-8"?> <bulkCmConfigDataFile" <xn:SubNetwork id="ONRM_ROOT"> <xn:MeContext id="PPP04156"> ... (4 Replies)
Discussion started by: pareshkp
4 Replies

10. UNIX for Beginners Questions & Answers

awk command to split pipe delimited file

Hello, I need to split a pipe de-limited file based on the COLUMN 7 value . If the column value changes I need to split the file Source File Payment|ID|DATE|TIME|CONTROLNUMBER|NUMBER|NAME|INDICATOR 42156974|1137937|10/1/2018|104440|4232|2054391|CARE|1... (9 Replies)
Discussion started by: rosebud123
9 Replies
DlfConverterProcess(3pm)				  LogReport's Lire Documentation				  DlfConverterProcess(3pm)

NAME
Lire::DlfConverterProcess - Object that controls the DLF conversion process SYNOPSIS
use Lire::ImportJob; use Lire::DlfStore; use Lire::DlfConverterProcess; my $src = new Lire::ImportJob( "file", 'pattern' => "/var/log/messages" ); my $store = Lire::DlfStore->open( "store" ); my $process = new Lire::DlfConverterProcess( $src, $store ); $process->run_import_job(); print "Log lines read: ", $process->line_count(), " "; print "DLF records created: ", $process->dlf_count, " "; print "Errors encountered: ", $process->errors_count, " "; print "Ignored records: ", $process->ignored_count," "; DESCRIPTION
This object encapsulates the Lire DLF conversion process. It takes as parameter a Lire::ImportJob and a Lire::DlfStore. It will setup the converter and will converter the content of Lire::ImportJob to DLF which will be saved in the Lire::DlfStore. The object provides the API to the converter. Methods are also available to query information on the conversion process. new( $job, $store ); Create a Lire::DlfConverterProcess that will be used to import the log specified in Lire::ImportJob into DLF records which will be stored into Lire::DlfStore. run_import_job( [$time] ) Import the log data from ImportJob as DLF. This method will throw an exception if it is called more than once. The $time parameter will be used to determine the time window covered by period. It defaults to the current time. job_id() Returns the job identifier associated to this process. dlf_store() Returns the Lire::DlfStore in which this conversion process is storing the DLF records. import_job() Returns the Lire::ImportJob upon which this conversion process is operating. line_count() Returns the number of lines processed. This will 0 in case the DLF converter process file and not log lines. During a processing, this is always equals to the line that is currently being converted. dlf_count() Returns the number of DLF records created. error_count() Returns the number of errors encountered in the conversion process. ignored_count() Returns the number of records which were ignored in the conversion process. saved_count() Returns the number of lines which were saved for later processing. API FOR THE DLF CONVERTERS
This is the object that encapsulates the Dlf implementation and hides the complexitity of the storage framework from the DLF converter. It offers the following methods to the DLf converter. write_dlf( $schema, $dlf ) This writes the $dlf DLF record conforming the $schema's schema in the Lire::DlfStore. The schema is the schema's name (e.g. 'www'). $dlf is an hash reference. Keys are the schema's field name. Undefined value means that this field isn't available in that record. save_log_line( $line ) Method that should be used to save $line for a future processing run of the converter on the same Lire::ImportJob. ignored_log_line( $line, [ $reason ] ) Method that can be used by the Lire::DlfConverter to report that the '$line' log line was ignored during that processing. The reason why the line was ignored can be given in $reason. For example, syslog-based converter should use that method to report lines that are for another 'service' than theirs. error( $error_msg, [ $line ] ); Method that should be used by the Lire::DlfConveter to report that an error was encountered when processing the Lire::ImportJob. $error_msg should be used to report the nature of the error. The $line parameter should be used by converter operating on lines to associate the error message to a particular line. SEE ALSO
Lire::DlfStore(3pm) Lire::DlfConverter(3pm) AUTHOR
Francis J. Lacoste <flacoste@logreport.org> VERSION
$Id: DlfConverterProcess.pm,v 1.18 2006/07/23 13:16:28 vanbaal Exp $ COPYRIGHT
Copyright (C) 2002-2004 Stichting LogReport Foundation LogReport@LogReport.org This file is part of Lire. Lire is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html. Lire 2.1.1 2006-07-23 DlfConverterProcess(3pm)
All times are GMT -4. The time now is 05:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy