Sponsored Content
Top Forums Shell Programming and Scripting include NULLs in line length check Post 302330234 by jim mcnamara on Tuesday 30th of June 2009 02:26:56 PM
Old 06-30-2009
Code:
wc -c datafile | read value junk
if [[  $$( $value % 161 )) -ne 0 ]] ; then
      echo "data file does not have 161 lrecl record(s)"
else
      echo "ok"
fi

If you have to check every single line try something like this
Code:
dd if=datafile of=testfile cbs=161 block
cksum datafile | read chk1 junk
cksum testfile | read chk2 junk
if [[ "$chk1" != "$chk2" ]] ; then
   echo data format error in datafile"
fi

 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check length of Shell Variable

I am using a Korn Shell script.. I need to verify the length of a variable.. ie number=12345 I need then to check 12345 to make sure its no longer than 5 digits... Can you help? (4 Replies)
Discussion started by: frustrated1
4 Replies

2. AIX

check length

I'm not familiar with unix. I need know how to check parameter (length) when i need check the userid. lets say my charaters is 3, how to check I must key-in 3 word before system can continue to another step echo "\n\n\n\tPlease Enter User ID: \c" read userid if then echo... (1 Reply)
Discussion started by: wanasmadi
1 Replies

3. Shell Programming and Scripting

How to check Null values in a file column by column if columns are Not NULLs

Hi All, I have a table with 10 columns. Some columns(2nd,4th,5th,7th,8th and 10th) are Not Null columns. I'll get a tab-delimited file and want to check col by col and generate seperate error code for each col eg:102 if 2nd col value is NULL and 104 if 4th col value is NULL so on... I am a... (7 Replies)
Discussion started by: Mandab
7 Replies

4. Shell Programming and Scripting

sort truncates line when they contain nulls

When I try to sort a file where some records contain nulls i.e. hex 00 the sort truncates the record when it reaches the null and writes message: "sort: warning: missing NEWLINE added at end of input file myfile" I'm assuming from this that the sort sees the null as a special character and... (6 Replies)
Discussion started by: ArthurWaik
6 Replies

5. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies

6. Shell Programming and Scripting

Check length of record

Hi, I have a problem, please help me, I have a flat file like this: P00000000088888888999999999 0000999903 000000000000000000 P00000000077777777000000000 0000999903 000000000000000000 P00000000044444444333333333 0000999903 00000000000000000079875 P00000000066666666111111111 0000999903 ... (5 Replies)
Discussion started by: DebianJ
5 Replies

7. Shell Programming and Scripting

perl file, one line code include "length, rindex, substr", slow

Hi Everyone, # cat a.txt a;b;c;64O a;b;c;d;ee;f # cat a.pl #!/usr/bin/perl use strict; use warnings; my $tmp3 = ",,a,,b,,c,,d,,e,,f,,"; open(my $FA, "a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\;/, $_); if ( ($tmp =~ m/^(64O)/i) || ($tmp... (3 Replies)
Discussion started by: jimmy_y
3 Replies

8. Shell Programming and Scripting

Check for length which exceeds specified length in a line

Hi, I have a issue, I need to loop through a comma delimited file and check for the length which exceeds specified length , if Yes truncate the string. But my problem is , I do not have to check for all the fields and the field lenght is not same for all the fields. For ex: Say my line... (9 Replies)
Discussion started by: rashmisb
9 Replies
SUBSTR_COMPARE(3)							 1							 SUBSTR_COMPARE(3)

substr_compare - Binary safe comparison of two strings from an offset, up to length characters

SYNOPSIS
int substr_compare (string $main_str, string $str, int $offset, [int $length], [bool $case_insensitivity = false]) DESCRIPTION
substr_compare(3) compares $main_str from position $offset with $str up to $length characters. PARAMETERS
o $main_str - The main string being compared. o $str - The secondary string being compared. o $offset - The start position for the comparison. If negative, it starts counting from the end of the string. o $length - The length of the comparison. The default value is the largest of the length of the $str compared to the length of $main_str less the $offset. o $case_insensitivity - If $case_insensitivity is TRUE, comparison is case insensitive. RETURN VALUES
Returns < 0 if $main_str from position $offset is less than $str, > 0 if it is greater than $str, and 0 if they are equal. If $offset is equal to or greater than the length of $main_str, or the $length is set and is less than 1 (prior to PHP 5.6), substr_compare(3) prints a warning and returns FALSE. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.6.0 | | | | | | | $length may now be 0. | | | | | 5.1.0 | | | | | | | Added the possibility to use a negative $offset. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A substr_compare(3) example <?php echo substr_compare("abcde", "bc", 1, 2); // 0 echo substr_compare("abcde", "de", -2, 2); // 0 echo substr_compare("abcde", "bcg", 1, 2); // 0 echo substr_compare("abcde", "BC", 1, 2, true); // 0 echo substr_compare("abcde", "bc", 1, 3); // 1 echo substr_compare("abcde", "cd", 1, 2); // -1 echo substr_compare("abcde", "abc", 5, 1); // warning ?> SEE ALSO
strncmp(3). PHP Documentation Group SUBSTR_COMPARE(3)
All times are GMT -4. The time now is 07:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy