Sponsored Content
Top Forums Shell Programming and Scripting Insert text between delimiter Post 302173454 by shamrock on Thursday 6th of March 2008 05:25:05 PM
Old 03-06-2008
Quote:
Originally Posted by ystee
Input: INSERT into caps.prodfile VALUES ('MK992','',,,,'','','');
Output: INSERT into caps.prodfile VALUES ('MK992','',NULL,NULL,NULL,'','','');

I've tried the following

sed 's/,,/,NULL,/g' prodfile.sql

but it only inserts the first NULL in each line.
And there are several hundred Insert statements in a file. Thanks.
Code:
awk -F"," '{
   for (i = 1; i <= NF; ++i) {
      if ($i == "")
         printf("NULL,")
      else {
         if (i < NF)
            printf("%s,", $i)
         else
            printf("%s\n", $i)
      }
   }
}' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

2. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

3. UNIX for Advanced & Expert Users

Insert Delimiter at fixed locations in a flat file

Hi Can somebody help me with solution for this PLEASE? I have a flat file and need to insert delimiters at fixed positions in all the lines so that I can easily convert into EXCEL with columns defined as per their width. For Example Here is the file { kkjhdhal sdfewss sdtereetyw... (7 Replies)
Discussion started by: jd_mca
7 Replies

4. Shell Programming and Scripting

insert delimiter

I have a data file that I would like to add delimiters to. Example: Turn This: 20110624000744000693000704000764 Into This: 20110624,000744,000693,000704,000764 I found this link but the only issue is I do not know how many colums I will have. The first field would needs to be 8... (9 Replies)
Discussion started by: oldman2
9 Replies

5. Shell Programming and Scripting

Selecting Specific Columns and Insert the delimiter TAB

Hi, I am writing a Perl Script for the below : I have a data file that consists of the header information which is 231 Lines and the footer information as 4 lines. The total number of line including the header and footer 1.2 Million with Pipe Delimited file. For example: Header Information:... (4 Replies)
Discussion started by: filter
4 Replies

6. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

7. Shell Programming and Scripting

[Solved] Insert tabs as delimiter

Hello all, I have an unstructured file with space as delimiter , which I want to structure. The output file should actually have only 5 columns with tab as delimiter. The 4th column can have only 3 values ( biological_process , cellular_component , molecular_function ) Here is how the... (12 Replies)
Discussion started by: ritakadm
12 Replies

8. Shell Programming and Scripting

Insert a new column with sequence number (Delimiter as comma)

Hi All, I have a file which has data like a,b c,d e,f g,h And I need to insert a new column at the begining with sequence no( 1 to n) 1,a,b 2,c,d 3,e,f 4,g,h Please let me know how to acheive this in unix (3 Replies)
Discussion started by: weknowd
3 Replies

9. Shell Programming and Scripting

Linux shell script to insert new lines based on delimiter count

The input file is a .dat file which is delimited by null (^@ in Linux). On a windows PC it looks something like this (numbers are masked with 1). https://i.imgur.com/nta2Gqp.jpg The entire file is in one row but it has multiple records - each record contains 80 fields i.e. there are 81 counts... (9 Replies)
Discussion started by: digitalnirvana
9 Replies

10. Shell Programming and Scripting

Insert a value between two empty delimiter in the file.

Would like to insert value between two empty delimiter and at the very last too if empty. $ cat customerleft.tbl 300|Customer#000000300|I0fJfo60DRqQ|7|17-165-193-5964|8084.92|\N|p fluffily among the slyly express grouches. furiously express instruct||||||||||||||||||||||||\N... (3 Replies)
Discussion started by: Mannu2525
3 Replies
OCI_FIELD_IS_NULL(3)													      OCI_FIELD_IS_NULL(3)

oci_field_is_null - Checks if a field in the currently fetched row is NULL

SYNOPSIS
bool oci_field_is_null (resource $statement, mixed $field) DESCRIPTION
Checks if the given $field from the current row of $statement is NULL. PARAMETERS
o $statement - A valid OCI statement identifier. o $field - Can be the field's index (1-based) or name. RETURN VALUES
Returns TRUE if $field is NULL, FALSE otherwise. EXAMPLES
Example #1 oci_field_name(3) example <?php // Create the table with: // CREATE TABLE mytab (c1 NUMBER); // INSERT INTO mytab VALUES (1); // INSERT INTO mytab VALUES (NULL); $conn = oci_connect("hr", "hrpwd", "localhost/XE"); if (!$conn) { $m = oci_error(); trigger_error(htmlentities($m['message']), E_USER_ERROR); } $stid = oci_parse($conn, "SELECT * FROM mytab"); oci_execute($stid); while (($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) != false) { $ncols = oci_num_fields($stid); for ($col = 1; $col <= $ncols; $col++) { var_dump(oci_field_is_null($stid, $col)); } } // Outputs: // bool(false) // bool(true) oci_free_statement($stid); oci_close($conn); ?> NOTES
Note In PHP versions before 5.0.0 you must use ocicolumnisnull(3) instead. This name still can be used, it was left as alias of oci_field_is_null(3) for downwards compatability. This, however, is deprecated and not recommended. PHP Documentation Group OCI_FIELD_IS_NULL(3)
All times are GMT -4. The time now is 12:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy