remove empty field


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers remove empty field
# 8  
Old 04-06-2012
Try:
Code:
#!/usr/bin/gawk -f

BEGIN{FS=OFS="|"}

{
   <do my stuff 1>

# need to remove empty fields at this stage

   gsub(/^\||\|$/,x)
   gsub(/\|\|/,FS)

# need to keep going with FS=OFS="|"

   <do my stuff 2>
}
1


Last edited by Scrutinizer; 04-06-2012 at 05:17 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using awk to remove duplicate line if field is empty

Hi all, I've got a file that has 12 fields. I've merged 2 files and there will be some duplicates in the following: FILE: 1. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, 100 2. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, (EMPTY) 3. CDC, 54321, TEST3,... (4 Replies)
Discussion started by: tugar
4 Replies

2. 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

3. Shell Programming and Scripting

How to detect empty field in awk ?

Hi ! programmers I have a need of detecting empty field in file my file looks like this 40.900|-71.600|1.6|20|1|1961|21.00|3.700||1|US|28035|10029370|31 40.900|-71.600|5.7|20|1|1961|21.00|3.700||1|US|28035|10029370|31 40.900|-71.600|7.8|20|1|1961|21.00|3.700||1|US|28035|10029370|31... (7 Replies)
Discussion started by: Dona Clara
7 Replies

4. Shell Programming and Scripting

print non empty column/field value

I have below file 25-09-2012 24-09-2012 19-09-2012 31-07-2012 30-04-2012 30-03-2012 ASIAEXFVNV N/A CEU 4 DMIRSOA N/A CAS 2 2 2 DMIRSOA N/A MIDMT 2 NFIAL22 N/A HVNY 11 11 11 NFIAL22 N/A NYAL3 11 11 11 NFIAL22 N/A NYCN 11 11 11 ... (4 Replies)
Discussion started by: manas_ranjan
4 Replies

5. Shell Programming and Scripting

awk - remove row if specific field is empty/blank

I have this text.filecharles darwin sam delight george washington johnson culper darwin sam delight micheal jackson penny lite and would like to remove the row, if the first field is blank. so the result would be: result.filecharles darwin sam ... (4 Replies)
Discussion started by: charles33
4 Replies

6. Shell Programming and Scripting

Using sed to remove lines where field is empty

I was just looking at this post: https://www.unix.com/shell-programming-scripting/22893-delete-multiple-empty-lines.html. and I am looking to achieve the same with sed. So the idea is to delete lines from a file where a certain field has no value. Inputfile: EMID MMDDYY HOURS JOB EMNAME 0241... (4 Replies)
Discussion started by: figaro
4 Replies

7. UNIX for Dummies Questions & Answers

Count of Field for Non-Empty

Hi Guys, I wanted to count the number of records for a particular field of a file. whose fields are separated by comma"," I fI use this command. cat "filename" cut -sd "," -f13 | wc -l This shows all the lines count including the blank values for the field number 13. I wanted to count... (2 Replies)
Discussion started by: Swapna173
2 Replies

8. Shell Programming and Scripting

How to print empty line when the a field is changed

Hi all, I have this input file .. BSS01 107 Swafieh 11/06/2008 12:06:57 BSS01 111 Ramada_Hotel 12/06/2008 11:37:20 BSS01 147 Kalha_Rep 11/06/2008 19:13:39 BSS01 147 Kalha_Rep ... (9 Replies)
Discussion started by: yahyaaa
9 Replies

9. Shell Programming and Scripting

Awk scrip to remove empty field

Hi I have a file which looks like this name: Sally group: Group4 name: Tim group: Group1 name: Dan group: Group2 name: Chris group: Group3 name: Peter group: name: Fred group: name: Mary group: Group2 Well I want to get rid of the... (4 Replies)
Discussion started by: bombcan
4 Replies

10. UNIX for Dummies Questions & Answers

Shell Script using Join, empty field help!

Deleted#### (1 Reply)
Discussion started by: tibbyuk
1 Replies
Login or Register to Ask a Question
MIME::Field::ContType(3pm)				User Contributed Perl Documentation				MIME::Field::ContType(3pm)

NAME
MIME::Field::ContType - a "Content-type" field DESCRIPTION
A subclass of Mail::Field. Don't use this class directly... its name may change in the future! Instead, ask Mail::Field for new instances based on the field name! SYNOPSIS
use Mail::Field; use MIME::Head; # Create an instance from some text: $field = Mail::Field->new('Content-type', 'text/HTML; charset="US-ASCII"'); # Get the MIME type, like 'text/plain' or 'x-foobar'. # Returns 'text/plain' as default, as per RFC 2045: my ($type, $subtype) = split('/', $field->type); # Get generic information: print $field->name; # Get information related to "message" type: if ($type eq 'message') { print $field->id; print $field->number; print $field->total; } # Get information related to "multipart" type: if ($type eq 'multipart') { print $field->boundary; # the basic value, fixed up print $field->multipart_boundary; # empty if not a multipart message! } # Get information related to "text" type: if ($type eq 'text') { print $field->charset; # returns 'us-ascii' as default } PUBLIC INTERFACE
boundary Return the boundary field. The boundary is returned exactly as given in the "Content-type:" field; that is, the leading double-hyphen ("--") is not prepended. (Well, almost exactly... from RFC 2046: (If a boundary appears to end with white space, the white space must be presumed to have been added by a gateway, and must be deleted.) so we oblige and remove any trailing spaces.) Returns the empty string if there is no boundary, or if the boundary is illegal (e.g., if it is empty after all trailing whitespace has been removed). multipart_boundary Like "boundary()", except that this will also return the empty string if the message is not a multipart message. In other words, there's an automatic sanity check. type Try real hard to determine the content type (e.g., "text/plain", "image/gif", "x-weird-type", which is returned in all-lowercase. A happy thing: the following code will work just as you would want, even if there's no subtype (as in "x-weird-type")... in such a case, the $subtype would simply be the empty string: ($type, $subtype) = split('/', $head->mime_type); If the content-type information is missing, it defaults to "text/plain", as per RFC 2045: Default RFC 2822 messages are typed by this protocol as plain text in the US-ASCII character set, which can be explicitly specified as "Content-type: text/plain; charset=us-ascii". If no Content-Type is specified, this default is assumed. Note: under the "be liberal in what we accept" principle, this routine no longer syntax-checks the content type. If it ain't empty, just downcase and return it. NOTES
Since nearly all (if not all) parameters must have non-empty values to be considered valid, we just return the empty string to signify missing fields. If you need to get the real underlying value, use the inherited "param()" method (which returns undef if the parameter is missing). SEE ALSO
MIME::Field::ParamVal, Mail::Field AUTHOR
Eryq (eryq@zeegee.com), ZeeGee Software Inc (http://www.zeegee.com). David F. Skoll (dfs@roaringpenguin.com) http://www.roaringpenguin.com perl v5.14.2 2012-06-08 MIME::Field::ContType(3pm)