The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed and whitespace characters SAMZ UNIX for Advanced & Expert Users 1 07-03-2008 01:11 PM
Split a file with no pattern -- Split, Csplit, Awk madhunk UNIX for Dummies Questions & Answers 10 12-17-2007 12:57 PM
Delete whitespace truck7758 Shell Programming and Scripting 12 12-05-2007 12:00 PM
sed : remove whitespace b.hamilton Shell Programming and Scripting 3 11-06-2007 11:02 AM
trim whitespace? msteudel Shell Programming and Scripting 4 07-07-2005 08:57 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-14-2008
theninja theninja is offline
Registered User
  
 

Join Date: Jan 2008
Location: St. Louis
Posts: 50
split whitespace help

I have a file that I am spliting and parsing, if data starts with an N/n toos it (which works) but I want it to also see if the data is blank and toss it.

What I have does not toss the blank space for dduck????

here is the data file and code I have.....

efudd 7546
bbunny N0542
tdevil 6666
dduck
mmouse 8888


Code:
open OUTER_HANDLE,"userids" or die "$!:$?";
while (<OUTER_HANDLE>) {
        my @userData = split;
        # print "DEBUG: Start... Number is [ $userData[1] ]\n";
        if ( ! ($userData[1] =~ /[n|N]/)
        or ! ($userData[1] =~ /\s/) ) {
               # print "DEBUG: userData[0] : [$userData[0]]\n";
               # print "DEBUG: userData[1] : [$userData[1]]\n";
                ripItOut( $userData[0], $userData[1] );
        }
}

close OUTER_HANDLE;

The usernames and numbers get printed out later on in the script. bbunny gets ignored as expected, but dduck prints out.
Thanks for any input.
theninja

Last edited by theninja; 07-14-2008 at 05:05 PM..
  #2 (permalink)  
Old 07-14-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
Is this what your looking for?


=---START---=

open OUTER_HANDLE,"names.txt" or die "$!:$?";
while (<OUTER_HANDLE>) {
my @userData = split(/ +/, $_);
# print "DEBUG: Start... Number is [ $userData[1] ]\n";
if ( trim($userData[0]) !~ /Nn/ && trim($userData[1]) !~ /Nn/ && $userData[1] != "" ) {
# print "DEBUG: userData[0] : [$userData[0]]\n";
# print "DEBUG: userData[1] : [$userData[1]]\n";
print" $userData[0], $userData[1]\n";
}
}

close OUTER_HANDLE;



sub trim($) {
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}

=---END---=
  #3 (permalink)  
Old 07-14-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Question a different way to approach the matter

Can you use the following logic?


Code:
> cat file99
efudd 7546
bbunny N0542
tdevil 6666
dduck
mmouse 8888
> cat file99 | grep [0-9][0-9] | grep -v [nN][0-9][0-9]
efudd 7546
tdevil 6666
mmouse 8888

  #4 (permalink)  
Old 07-15-2008
theninja theninja is offline
Registered User
  
 

Join Date: Jan 2008
Location: St. Louis
Posts: 50
Thanks for the replies,

I was able to get it to work with the following...


Code:
open OUTER_HANDLE,"userids" or die "$!:$?";
while (<OUTER_HANDLE>) {
        @userData = split;
                  $arraySize = @userData;
                  #print "DEBUG: Array size [$arraySize]\n";
                  if ( $arraySize == 2 ) {
                        # print "DEBUG: Start... Number is [$userData[1]]\n";
                        if ( ($userData[1] !~ /^N/) ) {
               #print "DEBUG: userData[0] : [$userData[0]]\n";
               #print "DEBUG: userData[1] : [$userData[1]]\n";
                ripItOut( $userData[0], $userData[1] );
                                }
        }
}

close OUTER_HANDLE;

Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0