Sponsored Content
Top Forums Shell Programming and Scripting Format the file by deleting empty field Post 302461327 by Scrutinizer on Sunday 10th of October 2010 10:38:00 AM
Old 10-10-2010
This variation should use less memory. It prints rows once they are full and it discards array elements that are no longer required:
Code:
awk '{ p=1
       for(i=1;i<=NF;i++)
       {
         if($i!~/ /)
         {
           N[i]++
           A[N[i],i]=$i
         }
         if(N[i]<=n)
           p=0
         fi
       }
       if(p)n++
       for (i=m+1;i<=n;i++)
         for (j=1;j<=NF;j++)
         {
           s=(j==NF)?RS:FS
           printf A[i,j]s
           delete A[i,j]
         }
       m=n
     }' FS=, infile


Last edited by Scrutinizer; 10-10-2010 at 11:45 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

change the empty function from the old format to the new format

I have about 300 files which has the function getDBBackend(). How to write a program to change the empty function from the old format to the new format? Old empty function format are either: function getDBBackend() { // Not available } // getDBBackend or: function... (0 Replies)
Discussion started by: powah
0 Replies

2. Shell Programming and Scripting

deleting the empty files

as of our requiremnt some x no of files will be created from a third party tool ,out of them one or two files will be empty i.e size is 0. so i want to remove those files which are empty. naming of the files which are created will be like this abc_.txt 0 size abc_1.txt 4000 size abc_2.txt... (1 Reply)
Discussion started by: srivsn
1 Replies

3. Shell Programming and Scripting

Deleting the empty file

Hi, I have a TEST.dat file. As a clean up process, I have to delete the TEST.dat file if it is empty. Basically, I don't want to delete TEST.dat if it contains anything in it but want to delete TEST.dat if it contains any spaces or nothing in it. Is there a command to check if the file... (2 Replies)
Discussion started by: rkumar28
2 Replies

4. Shell Programming and Scripting

awk - if field is empty, move line to new file

I have a script with this statement: /usr/xpg4/bin/awk -F"" 'NR==FNR{s=$2;next}{printf "%s\"%s\"\n", $0, s}' LOOKUP.TXT finallistnew.txt >test.txt I want to include logic or an additional step that says if there is no data in field 3, move the whole line out of test.txt into an additional... (9 Replies)
Discussion started by: scriptr2be
9 Replies

5. Shell Programming and Scripting

how I can add a constant to a field without changing the file format

Hi, I need to edit a file Protein Data Bank (pdb) and then open that file with the program VMD but when I edit the file with awk, it changes pdb format and the VMD program can not read it. I need to subtract 34 to field 6 ($ 6). this is a pdb file : ATOM 918 N GLY B 103 -11.855 8.675... (8 Replies)
Discussion started by: bio_
8 Replies

6. Shell Programming and Scripting

How to format file into comma separated field

Guys, Need you help, i have a a file content that look like this. Nokia 3330 <spaces><spaces><more spaces>+76451883874 Nokia 3610 +87467361615 so on and so forth, - there are so many spaces in between. - e.g.... (5 Replies)
Discussion started by: shtobias
5 Replies

7. Shell Programming and Scripting

Deleting empty folders

Hey, I need help with writing a shell script that deletes empty folders..anyone? :) Thank you! (5 Replies)
Discussion started by: putukas
5 Replies

8. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

9. Shell Programming and Scripting

How to remove empty field in a text file?

Hi all, I want to remove empty field in a text file. I tried to used sed. But it failed. Input: LG10_PM_map_19_LEnd 1000560 G AG AG LG10_PM_map_19_LEnd 1005621 G AG LG10_PM_map_19_LEnd 1011214 A AG AG LG10_PM_map_19_LEnd 1011673 T CT CT ... (3 Replies)
Discussion started by: huiyee1
3 Replies

10. UNIX for Beginners Questions & Answers

Command to extract empty field in a large UNIX file?

Hi All, I have records in unix file like below. In this file, we have empty fields from 4th Column to 22nd Column. I have some 200000 records in a file. I want to extract records only which have empty fields from 4th field to 22nd filed. This file is comma separated file. what is the unix... (2 Replies)
Discussion started by: rakeshp
2 Replies
ODBC_RESULT(3)								 1							    ODBC_RESULT(3)

odbc_result - Get result data

SYNOPSIS
mixed odbc_result (resource $result_id, mixed $field) DESCRIPTION
Get result data PARAMETERS
o $result_id - The ODBC resource. o $field - The field name being retrieved. It can either be an integer containing the column number of the field you want; or it can be a string containing the name of the field. RETURN VALUES
Returns the string contents of the field, FALSE on error, NULL for NULL data, or TRUE for binary data. EXAMPLES
The first call to odbc_result(3) returns the value of the third field in the current record of the query result. The second function call to odbc_result(3) returns the value of the field whose field name is "val" in the current record of the query result. An error occurs if a column number parameter for a field is less than one or exceeds the number of columns (or fields) in the current record. Similarly, an error occurs if a field with a name that is not one of the fieldnames of the table(s) that is(are) being queried. Example #1 odbc_result(3) examples <?php $item_3 = odbc_result($Query_ID, 3); $item_val = odbc_result($Query_ID, "val"); ?> NOTES
Field indices start from 1. Regarding the way binary or long column data is returned refer to odbc_binmode(3) and odbc_longreadlen(3). PHP Documentation Group ODBC_RESULT(3)
All times are GMT -4. The time now is 07:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy