Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to compare null and space using single if condition Post 302195436 by jayakumarrt on Thursday 15th of May 2008 05:43:43 AM
Old 05-15-2008
How to compare null and space using single if condition

Hi

I have a input file with many fields and each filed will be with in double quotes(""). i want to check fields contains balnk,null or space using condition using if. when i write code as below for if condition its not working

a=`awk -F ',' '{gsub("\"", "", $1);'NF==0';printf $1}' temp.txt`
echo $a

if [ -z "$a" ] || ["$a" = " " ]
then
echo "1st filed contains null or space please correct"
else
echo " field has data"
fi

Error message:

Account_SourceFile_Validation.sh[288]: [ : not found.

Can any one help on this.

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

compare null with non-null

I've got a very peculiar situation. I'm trying to find out if we can compare null fields with non-null. I've output csv files from SQL and Oracle. I need to compare each field from the files, and then find out any differences. The files usualy have over 500 fields, and send the resule to DBA.... (8 Replies)
Discussion started by: nitin
8 Replies

2. Shell Programming and Scripting

How can find Null value in If condition

Hi, i wrote If Conditions in my script, it's returns null and some values. but i am unable to find when Null value getting. bec we need modification according null vales. pls help me on this. (2 Replies)
Discussion started by: koti_rama
2 Replies

3. Shell Programming and Scripting

Cannot replace null with space

I have a fixed width text file which has some null characters in no particular order. I need to replace them with spaces so that the width remains same. I tried this: tr "\000" "\040" < mainfile > newfile Does not work. I tested that it works the other way round: $ echo "hello" |tr... (1 Reply)
Discussion started by: rikxik
1 Replies

4. UNIX for Advanced & Expert Users

How to Compare Null values??

Hi, Can someone help me comparing Null values. Scenario is as follows: I have a variable which "cache_prd" which can have either some integer or nothing(Null) if it is integer I have to again do some comparision but these comparisons give me this error:( "line 32: [: 95: unary operator... (3 Replies)
Discussion started by: Yagami
3 Replies

5. Shell Programming and Scripting

Stripping out more than a space from a line, but keep single space.

Hi all, Is there a way to perform the above, I am trying to strip out more than one space from a line, but keep the single space. See below output example. My Name is test test2 test3 test4 test5 My Name is test test2 test3 test4 test5 Please note that the lines would contain... (7 Replies)
Discussion started by: eo29
7 Replies

6. Shell Programming and Scripting

NULL in between, at begining or at end of line - convert to space

How to replace null with space? I want to make each line with 80 characters. If any line contains only 5 characters and remaining is null, then i want to make it as 80 characrets where 5 is original characters and remaining 75 characters will be null.. NULL can come in between the line,... (3 Replies)
Discussion started by: Amit.Sagpariya
3 Replies

7. Shell Programming and Scripting

How to compare 2 file with Condition.

Hello, I need to run a command or shell script that will compare 2 file with Condition. Can you please help ? thank you. File 1. ############start@linda22 ... ################## aaaaaaa bbbbbbb cccccc dddddd eeeee 11111 ############start@linda23 ... ################## aaaaaaa... (2 Replies)
Discussion started by: ooilinlove
2 Replies

8. Shell Programming and Scripting

Checking for null condition in a UNIX variable

i have this code for i in `cat sql_output.txt` do -- some script commands done sql_output.txt has 1 column with employee_ids If the sql_output.txt is null then the do loop should not execute. How can i implement this. for i in `cat sql_output.txt` If i is null or empty then ... (5 Replies)
Discussion started by: rafa_fed2
5 Replies

9. Shell Programming and Scripting

If condition to check null variable

Guys, Please help me on the below sample.cfg var=NULL sample.sh #!/bin/sh . /sample.cfg if ;then 1 st command here else 2 nd command here fi (3 Replies)
Discussion started by: AraR87
3 Replies

10. UNIX for Dummies Questions & Answers

To flat file, append null or space if its length is less than 10

Hi, We receive flat files with fixed width data Now our goal is append from right null or space to each record if the lenght of the record is less than for example 10. for example 123 45 6 0 123 45 123 45 6 123 and output should be 123 45 6 0 123 45**** 123 45 6**... (7 Replies)
Discussion started by: shharrath
7 Replies
ZZIP_DISK_FINDFILE(3)					       zziplib Function List					     ZZIP_DISK_FINDFILE(3)

NAME
zzip_disk_findfile, zzip_disk_findfirst, zzip_disk_findnext, zzip_disk_findmatch - search for files in the (mmapped) zip central directory SYNOPSIS
#include <zzip/mmapped.h> struct zzip_disk_entry * zzip_disk_findfile((ZZIP_DISK * disk, char *filename, struct zzip_disk_entry *after, zzip_strcmp_fn_t compare)); struct zzip_disk_entry * zzip_disk_findfirst((ZZIP_DISK * disk)); struct zzip_disk_entry * zzip_disk_findnext((ZZIP_DISK * disk, struct zzip_disk_entry *entry)); struct zzip_disk_entry * zzip_disk_findmatch((ZZIP_DISK * disk, char *filespec, struct zzip_disk_entry *after, zzip_fnmatch_fn_t compare, int flags)); DESCRIPTION
The zzip_disk_findfile function is given a filename as an additional argument, to find the disk_entry matching a given filename. The compare-function is usually strcmp or strcasecmp or perhaps strcoll, if null then strcmp is used. - use null as argument for "after"-entry when searching the first matching entry, otherwise the last returned value if you look for other entries with a special "compare" function (if null then a doubled search is rather useless with this variant of _findfile). The zzip_disk_findfirst function is the first call of all the zip access functions here. It contains the code to find the first entry of the zip central directory. Here we require the mmapped block to represent a real zip file where the disk_trailer is _last_ in the file area, so that its position would be at a fixed offset from the end of the file area if not for the comment field allowed to be of variable length (which needs us to do a little search for the disk_tailer). However, in this simple implementation we disregard any disk_trailer info telling about multidisk archives, so we just return a pointer to the zip central directory. For an actual means, we are going to search backwards from the end of the mmaped block looking for the PK-magic signature of a disk_trailer. If we see one then we check the rootseek value to find the first disk_entry of the root central directory. If we find the correct PK-magic signature of a disk_entry over there then we assume we are done and we are going to return a pointer to that label. The return value is a pointer to the first zzip_disk_entry being checked to be within the bounds of the file area specified by the arguments. If no disk_trailer was found then null is returned, and likewise we only accept a disk_trailer with a seekvalue that points to a disk_entry and both parts have valid PK-magic parts. Beyond some sanity check we try to catch a common brokeness with zip archives that still allows us to find the start of the zip central directory. The zzip_disk_findnext function takes an existing disk_entry in the central root directory (e.g. from zzip_disk_findfirst) and returns the next entry within in the given bounds of the mmapped file area. The zzip_disk_findmatch function uses a compare-function with an additional argument and it is called just like fnmatch(3) from POSIX.2 AD:1993), i.e. the argument filespec first and the ziplocal filename second with the integer-flags put in as third to the indirect call. If the platform has fnmatch available then null-compare will use that one and otherwise we fall back to mere strcmp, so if you need fnmatch searching then please provide an implementation somewhere else. - use null as argument for "after"-entry when searching the first matching entry, or the last disk_entry return-value to find the next entry matching the given filespec. AUTHOR
o Guido Draheim <guidod@gmx.de> COPYRIGHT
Copyright (c) 2003,2004,2006 Guido Draheim All rights reserved, use under the restrictions of the Lesser GNU General Public License or alternatively the restrictions of the Mozilla Public License 1.1 zziplib 0.13.62 ZZIP_DISK_FINDFILE(3)
All times are GMT -4. The time now is 12:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy