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
slabrd.f(3)							      LAPACK							       slabrd.f(3)

NAME
slabrd.f - SYNOPSIS
Functions/Subroutines subroutine slabrd (M, N, NB, A, LDA, D, E, TAUQ, TAUP, X, LDX, Y, LDY) SLABRD reduces the first nb rows and columns of a general matrix to a bidiagonal form. Function/Subroutine Documentation subroutine slabrd (integerM, integerN, integerNB, real, dimension( lda, * )A, integerLDA, real, dimension( * )D, real, dimension( * )E, real, dimension( * )TAUQ, real, dimension( * )TAUP, real, dimension( ldx, * )X, integerLDX, real, dimension( ldy, * )Y, integerLDY) SLABRD reduces the first nb rows and columns of a general matrix to a bidiagonal form. Purpose: SLABRD reduces the first NB rows and columns of a real general m by n matrix A to upper or lower bidiagonal form by an orthogonal transformation Q**T * A * P, and returns the matrices X and Y which are needed to apply the transformation to the unreduced part of A. If m >= n, A is reduced to upper bidiagonal form; if m < n, to lower bidiagonal form. This is an auxiliary routine called by SGEBRD Parameters: M M is INTEGER The number of rows in the matrix A. N N is INTEGER The number of columns in the matrix A. NB NB is INTEGER The number of leading rows and columns of A to be reduced. A A is REAL array, dimension (LDA,N) On entry, the m by n general matrix to be reduced. On exit, the first NB rows and columns of the matrix are overwritten; the rest of the array is unchanged. If m >= n, elements on and below the diagonal in the first NB columns, with the array TAUQ, represent the orthogonal matrix Q as a product of elementary reflectors; and elements above the diagonal in the first NB rows, with the array TAUP, represent the orthogonal matrix P as a product of elementary reflectors. If m < n, elements below the diagonal in the first NB columns, with the array TAUQ, represent the orthogonal matrix Q as a product of elementary reflectors, and elements on and above the diagonal in the first NB rows, with the array TAUP, represent the orthogonal matrix P as a product of elementary reflectors. See Further Details. LDA LDA is INTEGER The leading dimension of the array A. LDA >= max(1,M). D D is REAL array, dimension (NB) The diagonal elements of the first NB rows and columns of the reduced matrix. D(i) = A(i,i). E E is REAL array, dimension (NB) The off-diagonal elements of the first NB rows and columns of the reduced matrix. TAUQ TAUQ is REAL array dimension (NB) The scalar factors of the elementary reflectors which represent the orthogonal matrix Q. See Further Details. TAUP TAUP is REAL array, dimension (NB) The scalar factors of the elementary reflectors which represent the orthogonal matrix P. See Further Details. X X is REAL array, dimension (LDX,NB) The m-by-nb matrix X required to update the unreduced part of A. LDX LDX is INTEGER The leading dimension of the array X. LDX >= max(1,M). Y Y is REAL array, dimension (LDY,NB) The n-by-nb matrix Y required to update the unreduced part of A. LDY LDY is INTEGER The leading dimension of the array Y. LDY >= max(1,N). Author: Univ. of Tennessee Univ. of California Berkeley Univ. of Colorado Denver NAG Ltd. Date: September 2012 Further Details: The matrices Q and P are represented as products of elementary reflectors: Q = H(1) H(2) . . . H(nb) and P = G(1) G(2) . . . G(nb) Each H(i) and G(i) has the form: H(i) = I - tauq * v * v**T and G(i) = I - taup * u * u**T where tauq and taup are real scalars, and v and u are real vectors. If m >= n, v(1:i-1) = 0, v(i) = 1, and v(i:m) is stored on exit in A(i:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i). If m < n, v(1:i) = 0, v(i+1) = 1, and v(i+1:m) is stored on exit in A(i+2:m,i); u(1:i-1) = 0, u(i) = 1, and u(i:n) is stored on exit in A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i). The elements of the vectors v and u together form the m-by-nb matrix V and the nb-by-n matrix U**T which are needed, with X and Y, to apply the transformation to the unreduced part of the matrix, using a block update of the form: A := A - V*Y**T - X*U**T. The contents of A on exit are illustrated by the following examples with nb = 2: m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n): ( 1 1 u1 u1 u1 ) ( 1 u1 u1 u1 u1 u1 ) ( v1 1 1 u2 u2 ) ( 1 1 u2 u2 u2 u2 ) ( v1 v2 a a a ) ( v1 1 a a a a ) ( v1 v2 a a a ) ( v1 v2 a a a a ) ( v1 v2 a a a ) ( v1 v2 a a a a ) ( v1 v2 a a a ) where a denotes an element of the original matrix which is unchanged, vi denotes an element of the vector defining H(i), and ui an element of the vector defining G(i). Definition at line 210 of file slabrd.f. Author Generated automatically by Doxygen for LAPACK from the source code. Version 3.4.2 Tue Sep 25 2012 slabrd.f(3)
All times are GMT -4. The time now is 03:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy