Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Splitting a file and sending results to another file Post 302455207 by ladyAnne on Tuesday 21st of September 2010 05:11:16 AM
Old 09-21-2010
Splitting a file and sending results to another file

Hi

Here is my script:

Code:
 
#!/bin/bash
set -x
dir="/var/local/dsx/import"
gawk -F, '
 $1 == last1 && $2 == last2 {
  printf $0"\n" >> $dir/$2
 }
 $1 !=last1 || $2 != last2 {
  printf $0"\n" >> $dir/$2
 }
 {
  last1=$1
  last2=$2 
 } 
 '  $1

Here is my test file:

Code:
 
o,e,r
1,2,3
1,2,3
1,2,3
4,5,6
4,5,6
4,5,6
4,5,6
4,5,6
4,5,6

Basically I want to split my file and send the haf to another file, but I get this error:
Code:
gawk: cmd. line:5: (FILENAME=t FNR=1) fatal: division by zero attempted

Can somebody please help
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Splitting a file based on record sin another file

All, We receive a file with a large no of records (records can vary) and we have to split it into two files based on another file. e.g. File1: UHDR 2008112 "25187","00000022","00",21-APR-1991,"" ,"D",-000000519,+0000000000,"C", ,+000000000,+000000000,000000000,"2","" ,21-APR-1991... (7 Replies)
Discussion started by: er_ashu
7 Replies

2. Shell Programming and Scripting

File splitting, naming file according to internal field

Hi All, I have a rather stange set of requirements that I'm hoping someone here could help me with. We receive a file that is actually a concatenation of 4 files (don't believe this would change, but ideally the solution would handle n files). The super-file looks like:... (7 Replies)
Discussion started by: Leedor
7 Replies

3. Shell Programming and Scripting

Splitting a file in to multiple files and passing each individual file to a command

I have an input file with contents like: MainFile.dat: 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 ... (4 Replies)
Discussion started by: rkrish
4 Replies

4. UNIX for Dummies Questions & Answers

Pipe binary file matches grep results to file

I am using grep to match a pattern, but the output is strange. $ grep -r -o "pattern" * Gives me: Binary file foo1 matches Binary file foo2 matches Binary file foo3 matches To find the lines before/after, I then have to use the following on each file: $ strings foo1 | grep -A1 -B1... (0 Replies)
Discussion started by: chipperuga
0 Replies

5. UNIX for Dummies Questions & Answers

Extracting data from one file, based on another file (splitting)

Dear All, I have two files but want to extract data from one based on another... can you please help me file 1 David Tom Ellen and file 2 David|0010|testnamez|resultsz David|0004|testnamex|resultsx Tom|0010|testnamez|resultsz Tom|0004|testnamex|resultsx Ellen|0010|testnamez|resultsz... (12 Replies)
Discussion started by: A-V
12 Replies

6. Shell Programming and Scripting

Splitting XML file on basis of line number into multiple file

Hi All, I have more than half million lines of XML file , wanted to split in four files in a such a way that top 7 lines should be present in each file on top and bottom line of should be present in each file at bottom. from the 8th line actual record starts and each record contains 15 lines... (14 Replies)
Discussion started by: ajju
14 Replies

7. Shell Programming and Scripting

Execution of loop :Splitting a single file into multiple .dat file

hdr=$(cut -c1 $path$file|head -1)#extract header”H” trl=$(cut -c|path$file|tail -1)#extract trailer “T” SplitFile=$(cut -c 50-250 $path 1$newfile |sed'$/ *$//' head -1')# to trim white space and extract table name If; then # start loop if it is a header While read I #read file Do... (4 Replies)
Discussion started by: SwagatikaP1
4 Replies

8. Shell Programming and Scripting

Splitting a text file into smaller files with awk, how to create a different name for each new file

Hello, I have some large text files that look like, putrescine Mrv1583 01041713302D 6 5 0 0 0 0 999 V2000 2.0928 -0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 5.6650 0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 3.5217 ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

9. UNIX for Beginners Questions & Answers

Splitting the file based on two fields - Fixed length file

Hi , I am having a scenario where I need to split the file based on two field values. The file is a fixed length file. ex: AA0998703000000000000190510095350019500010005101980301 K 0998703000000000000190510095351019500020005101480 ... (4 Replies)
Discussion started by: saj
4 Replies

10. Shell Programming and Scripting

Create a text file and a pdf file from Linux command results.

Hello. The task : Using multiple commands like : gdisk -l $SOME_DISK >> $SOME_FILEI generate some text file. For readiness I must insert page break. When the program is finished I want to convert the final text file to a pdf file. When finished, I got two files : One text file and One pdf... (1 Reply)
Discussion started by: jcdole
1 Replies
std::numpunct< _CharT >(3)				     Library Functions Manual					std::numpunct< _CharT >(3)

NAME
std::numpunct< _CharT > - SYNOPSIS
Inherits std::locale::facet. Inherited by std::numpunct_byname< _CharT >. Public Types typedef __numpunct_cache< _CharT > __cache_type typedef _CharT char_type typedef basic_string< _CharT > string_type Public Member Functions numpunct (size_t __refs=0) numpunct (__cache_type *__cache, size_t __refs=0) numpunct (__c_locale __cloc, size_t __refs=0) char_type decimal_point () const string_type falsename () const string grouping () const char_type thousands_sep () const string_type truename () const Static Public Attributes static locale::id id Protected Member Functions virtual ~numpunct () void _M_initialize_numpunct (__c_locale __cloc=0) template<> void _M_initialize_numpunct (__c_locale __cloc) template<> void _M_initialize_numpunct (__c_locale __cloc) virtual char_type do_decimal_point () const virtual string_type do_falsename () const virtual string do_grouping () const virtual char_type do_thousands_sep () const virtual string_type do_truename () const Static Protected Member Functions static __c_locale _S_clone_c_locale (__c_locale &__cloc) throw () static void _S_create_c_locale (__c_locale &__cloc, const char *__s, __c_locale __old=0) static void _S_destroy_c_locale (__c_locale &__cloc) static __c_locale _S_get_c_locale () static const char * _S_get_c_name () throw () static __c_locale _S_lc_ctype_c_locale (__c_locale __cloc, const char *__s) Protected Attributes __cache_type * _M_data Detailed Description template<typename _CharT>class std::numpunct< _CharT > Primary class template numpunct. This facet stores several pieces of information related to printing and scanning numbers, such as the decimal point character. It takes a template parameter specifying the char type. The numpunct facet is used by streams for many I/O operations involving numbers. The numpunct template uses protected virtual functions to provide the actual results. The public accessors forward the call to the virtual functions. These virtual functions are hooks for developers to implement the behavior they require from a numpunct facet. Definition at line 1641 of file locale_facets.h. Member Typedef Documentation template<typename _CharT > typedef _CharT std::numpunct< _CharT >::char_type Public typedefs. Definition at line 1647 of file locale_facets.h. template<typename _CharT > typedef basic_string<_CharT> std::numpunct< _CharT >::string_type Public typedefs. Definition at line 1648 of file locale_facets.h. Constructor &; Destructor Documentation template<typename _CharT > std::numpunct< _CharT >::numpunct (size_t__refs = 0) [inline], [explicit] Numpunct constructor. Parameters: __refs Refcount to pass to the base class. Definition at line 1665 of file locale_facets.h. template<typename _CharT > std::numpunct< _CharT >::numpunct (__cache_type *__cache, size_t__refs = 0) [inline], [explicit] Internal constructor. Not for general use. This is a constructor for use by the library itself to set up the predefined locale facets. Parameters: __cache __numpunct_cache object. __refs Refcount to pass to the base class. Definition at line 1679 of file locale_facets.h. template<typename _CharT > std::numpunct< _CharT >::numpunct (__c_locale__cloc, size_t__refs = 0) [inline], [explicit] Internal constructor. Not for general use. This is a constructor for use by the library itself to set up new locales. Parameters: __cloc The C locale. __refs Refcount to pass to the base class. Definition at line 1693 of file locale_facets.h. template<typename _CharT > virtual std::numpunct< _CharT >::~numpunct () [protected], [virtual] Destructor. Member Function Documentation template<typename _CharT > char_type std::numpunct< _CharT >::decimal_point () const [inline] Return decimal point character. This function returns a char_type to use as a decimal point. It does so by returning returning numpunct<char_type>::do_decimal_point(). Returns: char_type representing a decimal point. Definition at line 1707 of file locale_facets.h. template<typename _CharT > virtual char_type std::numpunct< _CharT >::do_decimal_point () const [inline], [protected], [virtual] Return decimal point character. Returns a char_type to use as a decimal point. This function is a hook for derived classes to change the value returned. Returns: char_type representing a decimal point. Definition at line 1794 of file locale_facets.h. template<typename _CharT > virtual string_type std::numpunct< _CharT >::do_falsename () const [inline], [protected], [virtual] Return string representation of bool false. Returns a string_type containing the text representation for false bool variables. This function is a hook for derived classes to change the value returned. Returns: string_type representing printed form of false. Definition at line 1845 of file locale_facets.h. template<typename _CharT > virtual string std::numpunct< _CharT >::do_grouping () const [inline], [protected], [virtual] Return grouping specification. Returns a string representing groupings for the integer part of a number. This function is a hook for derived classes to change the value returned. See Also: grouping() for details. Returns: String representing grouping specification. Definition at line 1819 of file locale_facets.h. template<typename _CharT > virtual char_type std::numpunct< _CharT >::do_thousands_sep () const [inline], [protected], [virtual] Return thousands separator character. Returns a char_type to use as a thousands separator. This function is a hook for derived classes to change the value returned. Returns: char_type representing a thousands separator. Definition at line 1806 of file locale_facets.h. template<typename _CharT > virtual string_type std::numpunct< _CharT >::do_truename () const [inline], [protected], [virtual] Return string representation of bool true. Returns a string_type containing the text representation for true bool variables. This function is a hook for derived classes to change the value returned. Returns: string_type representing printed form of true. Definition at line 1832 of file locale_facets.h. template<typename _CharT > string_type std::numpunct< _CharT >::falsename () const [inline] Return string representation of bool false. This function returns a string_type containing the text representation for false bool variables. It does so by calling numpunct<char_type>::do_falsename(). Returns: string_type representing printed form of false. Definition at line 1777 of file locale_facets.h. template<typename _CharT > string std::numpunct< _CharT >::grouping () const [inline] Return grouping specification. This function returns a string representing groupings for the integer part of a number. Groupings indicate where thousands separators should be inserted in the integer part of a number. Each char in the return string is interpret as an integer rather than a character. These numbers represent the number of digits in a group. The first char in the string represents the number of digits in the least significant group. If a char is negative, it indicates an unlimited number of digits for the group. If more chars from the string are required to group a number, the last char is used repeatedly. For example, if the grouping() returns '0302' and is applied to the number 123456789, this corresponds to 12,34,56,789. Note that if the string was '32', this would put more than 50 digits into the least significant group if the character set is ASCII. The string is returned by calling numpunct<char_type>::do_grouping(). Returns: string representing grouping specification. Definition at line 1751 of file locale_facets.h. template<typename _CharT > char_type std::numpunct< _CharT >::thousands_sep () const [inline] Return thousands separator character. This function returns a char_type to use as a thousands separator. It does so by returning returning numpunct<char_type>::do_thousands_sep(). Returns: char_type representing a thousands separator. Definition at line 1720 of file locale_facets.h. template<typename _CharT > string_type std::numpunct< _CharT >::truename () const [inline] Return string representation of bool true. This function returns a string_type containing the text representation for true bool variables. It does so by calling numpunct<char_type>::do_truename(). Returns: string_type representing printed form of true. Definition at line 1764 of file locale_facets.h. Member Data Documentation template<typename _CharT > locale::id std::numpunct< _CharT >::id [static] Numpunct facet id. Definition at line 1657 of file locale_facets.h. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Jun 10 2014 std::numpunct< _CharT >(3)
All times are GMT -4. The time now is 11:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy