472,958 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

awk's NF in Perl

Hi all,

I want to have the awk NF variable in Perl. Yes I know there are many
hints for that. But I only found the folloing:

#!/usr/bin/perl

$ln="1;2;3;4;;;;;;10";
$nf = @records = split(/;/, $ln);
print "NF:$nf\n";
$"=";";
print "@records\n";

output:
NF:10
1;2;3;4;;;;;;10

so it looks good, now I change the script a little bit, look here:

# change this line in script:
$ln="1;2;3;4;;;;;;";

output:
NF:4
1;2;3;4

So now you can see the trick with spilt did not work any time. Are
there any other suggestions out there?

ciao
Thorsten
Jul 19 '05 #1
1 4727
In article <be*************************@posting.google.com> , Thorsten
Gottschalk <iq****@web.de> wrote:
Hi all,

I want to have the awk NF variable in Perl. Yes I know there are many
hints for that. But I only found the folloing:

#!/usr/bin/perl
use strcit:
use warnings;

$ln="1;2;3;4;;;;;;10";
my $ln = "1;2;3;4;;;;;;;";
$nf = @records = split(/;/, $ln);
my $nf = my @records = split(/;/, $ln, -1 );
print "NF:$nf\n";
$"=";";
print "@records\n";

output:
NF:10
1;2;3;4;;;;;;10

so it looks good, now I change the script a little bit, look here:

# change this line in script:
$ln="1;2;3;4;;;;;;";

output:
NF:4
1;2;3;4
NF:10
1;2;3;4;;;;;;;

So now you can see the trick with spilt did not work any time. Are
there any other suggestions out there?

ciao
Thorsten


Check the documentation on split:

perldoc -f split

FYI: this newgroup is defunct. Try comp.lang.perl.misc in the future.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dan Jacobson | last post by:
An old dog can't learn new tricks, so where's the a2py awk to python translator? Perl has a2p. E.g. today I wonder how to do '{print $1}', well with a2p I know how to do it in perl, but with...
20
by: Matthew Thorley | last post by:
My friend sent me an email asking this: > I'm attemtping to decide which scripting language I should master and > was wondering if it's possible to do > these unixy awkish commands in python:...
13
by: NNTP | last post by:
I have a script that outputs the following. 200 23.131.155.5; 1 23.131.161.4; 2 102.131.161.54; 2 23.160.180.4; 35 54.1.8.7; 356 15.18.235.52; 1 205.18.235.88; 1 205.18.246.21;
2
by: gorda | last post by:
Hello, Using sed or awk, I can quickly parse and perform operations on the command line itself as in: cat file | sed 's/cat/dog' cat file | awk ' /cat/ {print "found the cat"} ' How can i...
2
by: NNTP | last post by:
I have a file with the following data 192.168.60.161 DOMAINNAME-POWER 03U 192.168.60.161 DOMAINNAME-TEMP 1eU 192.168.60.161 MAC 00-xy-zz-07-bd-8a 192.168.60.179 DOMAINNAME-abacdf ...
3
by: Anthony Smith | last post by:
Greetings, I have the need to take a file and remove the trailing white space as well as any empty lines... I inherited this script: cat $1 | awk -v quote="'" \ ' /^*$/ { next;...
1
Colloid Snake
by: Colloid Snake | last post by:
Hey everyone. I'm currently attempting to band-aid an horrible use of a Cacti implementation (and I swear, this is only temporary! No, really! They told me it's in the budget for next year, and has...
2
by: Amzul | last post by:
hello all i yet to start this project. i need some edvice. i want to insert to my db few fix words from a .txt file what is the best language to write it? awk or perl ? i can write it...
15
by: jyo123 | last post by:
Hi everyone, I have a file input.txt which has contents like this: 1 1132 aaaa vvvv 2 1123 bbbb 222 3 1121 ssad 323 4 2222 asda 232 When i was scripting in shell i used awk to pick 2nd row...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.