Sponsored Content
Top Forums Shell Programming and Scripting Format the file by deleting empty field Post 302461324 by Scrutinizer on Sunday 10th of October 2010 09:57:16 AM
Old 10-10-2010
If you have enough memory:
Code:
awk '{ for(i=1;i<=NF;i++)
         if($i!~/ /)
         {
           N[i]++
           A[N[i],i]=$i
         }
     }
     END {
       for (i=1;i<=N[1];i++)
       {
         for (j=1;j<NF;j++)
           printf A[i,j]FS
         print A[i,NF]
       }
     }' FS=, infile

 

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
DBS_UPDATE(1p)						User Contributed Perl Documentation					    DBS_UPDATE(1p)

NAME
dbs_update - Update SQL Databases DESCRIPTION
dbs_update is an utility to update SQL databases from text files. FORMAT OF THE TEXT FILES dbs_update assumes that each line of the input contains a data record and that the field within the records are separated by tabulators. You can tell dbs_update about the input format with the --format option. The first field of the data record is used as table specification. These consists of the table name and optionally the index of starting column, separated by a dot. Alternatively dbs_update can read the column names from the first line of input (see the -h/--headline option). These can even be aliases for the real column names (see the -m/--map option). COMMAND LINE PARAMETERS
Required command line parameters are the DBI driver ("Pg" for Postgres or "mysql" for MySQL) and the database name. The third parameter is optionally and specifies the database user and/or the host where the database resides ("racke", "racke@linuxia.de" or "@linuxia.de"). OPTIONS
--cleanse Removes all records which remain unaffected from the update process. The same result as deleting all records from the table first and then running dbs_update, but the table is not empty in the meantime. -c COLUMN,COLUMN,..., --columns=COLUMN,COLUMN,... Update only the table columns given by the COLUMN parameters. To exclude columns from the update prepend "!" or "^" to the parameters. --rows=ROW,ROW,... Update only the input rows given by the ROW parameters. The first row is 1 where headlines doesn't count. To exclude rows from the update prepend "!" or "^" to the parameters. -f FILE, --file=FILE Reads records from file FILE instead of from standard input. --format=FORMAT[SEPCHAR] Assumes FORMAT as format for the input. Only CSV can be specified for now, default is TAB. The default field separator for CSV is a comma, you may change this by appending the separator to the format. -h, --headline Reads the column names from the first line of the input instead of dedicting them from the database layout. Requires the -t/--table option. -k COUNT, -k KEY,KEY,..., --keys=COUNT, --keys=KEY,KEY,... Specifies the keys for the table(s) either as the number of columns used as keys or by specifying them explicitly as comma separated argu- ments to the option. This is used for the detection of existing records. -m ALIASDEF, --map=ALIASDEF Maps the names found in the first line of input to the actual column names in the database. The alias and the column name are separated with "=" signs and the different entries are separated by ";" signs, e.g. "Art-No.=code;Short Description=shortdescr'". --map-filter=FILTER Applies a filter to the column names read from the input file. Currently there is only the "lc" filter available. --match-sql=FIELD:{STATEMENT} Updates only records where the value of the column FIELD is in the result set of the SQL statement STATEMENT, e.g. "category:{select dis- tinct name from categories}". -o, --update-only Updates existing database entries only, stops if it detects new ones. -r ROUTINE, --routine=ROUTINE Applies ROUTINE to any data record. ROUTINE must be a subroutine. dbs_update passes the table name and a hash reference to this subrou- tine. The keys of the hash are the column names and the values are the corresponding field values. If the return value of ROUTINE is not a truth value, the data record will be skipped. "sub {my ($table, $valref) = @_; unless (defined $$valref{country} && $$valref{country} !~ /S/) { $$valref{country} = "Germany"; } 1; }" --skipbadlines Lines not matching the assumed format are ignored. Without this option, dbs_update simply stops. -t TABLE, --table=TABLE Uses TABLE as table name for all records instead of the first field name. AUTHOR
Stefan Hornburg (Racke), racke@linuxia.de SEE ALSO
perl(1), DBIx::Easy(3) perl v5.8.8 2007-02-01 DBS_UPDATE(1p)
All times are GMT -4. The time now is 04:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy