perl as awk replacement in a script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl as awk replacement in a script.
# 1  
Old 09-02-2008
perl as awk replacement in a script.

Hey all, Im trying to write a script on windows, which Im not too familiar with. Im generally a bash scripting guy but am using perl for this case.

My question is...

I have this exact output:

Code:
               2 Dir(s)   6,380,429,312 bytes free

and I just need to get the number out of that line. So, in unix I would just use `awk '{print $3}' filename.txt` but thats not an option in this case... is see many one line examples for perl, but none work which I assume is due to the whitepaces. and ontop of that I cant figure out how to take those one line statements and put them into a script Smilie

here is all I have got so far (its not much Smilie ).

Code:
$dirinfo = `dir | find "bytes free"`;
open diskinfo, ">diskinfo.txt";
print diskinfo $dirinfo;
close diskinfo;

# 2  
Old 09-02-2008
This is a Windows question; why are you not asking it in a Windows forum?
# 3  
Old 09-02-2008
Quote:
Originally Posted by cfajohnson
This is a Windows question; why are you not asking it in a Windows forum?
because it is a perl question.
# 4  
Old 09-02-2008
Echo your awk line through a2p to convert to perl....
Code:
$ echo '{print $3}' | a2p
#!/usr/bin/perl5.8.8
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
    if $running_under_some_shell;
                        # this emulates #! processing on NIH machines.
                        # (remove #! line above if indigestible)

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
                        # process any FOO=bar switches

$, = ' ';               # set output field separator
$\ = "\n";              # set output record separator

while (<>) {
    ($Fld1,$Fld2,$Fld3) = split(' ', $_, -1);
    print $Fld3;
}

# 5  
Old 09-02-2008
Quote:
Originally Posted by Ygor
Echo your awk line through a2p to convert to perl....
Code:
$ echo '{print $3}' | a2p
#!/usr/bin/perl5.8.8
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
    if $running_under_some_shell;
                        # this emulates #! processing on NIH machines.
                        # (remove #! line above if indigestible)

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
                        # process any FOO=bar switches

$, = ' ';               # set output field separator
$\ = "\n";              # set output record separator

while (<>) {
    ($Fld1,$Fld2,$Fld3) = split(' ', $_, -1);
    print $Fld3;
}

ohh, I did not even know about a2p just looked it up. I should be able to figure this out now. Thanks!

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Resample time series data with replacement any way to do this in awk or just bash script

I have some time series data that I need to resample or downsample at some specific time intervals. The firs column is time in decimal hours. I am tryiong to resample this data every 3 minutse. So I need a data value ever 0.05. Here is the example data and as you can see, there time slot for 0.1500... (3 Replies)
Discussion started by: malandisa
3 Replies

2. Shell Programming and Scripting

Word replacement in Perl

I have the following string : Cat dog fox catepillar bear foxy I need to replace "cat" and "fox" words from this sentence to word "animal" I do the following: $Str1="cat"; $Str2="fox"; $NewStr="animal"; open(F1, "<$inputFile") or die "Error: $!"; open(F2, ">$outputFile") or... (1 Reply)
Discussion started by: AIX_30
1 Replies

3. Shell Programming and Scripting

Perl Array Elements Replacement

Hello, I have the following perl array: @longname = (Fasthernet0/0 Fasthernet0/1 Serial0/1/0 Serial0/2/1 Tunnel55 Tunnel77) with the followinh array: @shortname = (Fa0/0 Fa0/1 Se0/1/0 Se0/2/1 Tu55 Tu77) in other words, I need to remove the following from each element in the array... (4 Replies)
Discussion started by: ahmed_zaher
4 Replies

4. Shell Programming and Scripting

need a perl replacement for this double for loop

hi everybody, can you help me with this? important: it has to be a pure perl code. zz.lis: accessibility arabic archivers astro audio benchmarks . . . "ls accessibility | grep -v Makefile" outputs accerciser at-poke at-spi at-spi-reference (6 Replies)
Discussion started by: pseudocoder
6 Replies

5. Shell Programming and Scripting

HELP Need in SED/PERL conditional line replacement

Hi , I need some help on perl/sed conditional replacement The situation is like below . I have a file contents like below . AAA|BBB|CCC|DDD AAA|BCF|CCC|HHH AAA|BVF|JJJ|KKK Here in the above file . I know my second column value (taking "|" as my delimited ) Basically I have to... (3 Replies)
Discussion started by: robin.r888
3 Replies

6. UNIX for Dummies Questions & Answers

Simple awk script for positional replacement in text?

I have a string of letters. (They happen to be DNA, not that it's relevant to the question.) For analysis purposes, I need to replace the information at some of the sites. I need to do this based on their position, not the information in that position. I also need to ignore differences at other... (10 Replies)
Discussion started by: JFS
10 Replies

7. Shell Programming and Scripting

Replacement of sentence in perl

Hi, I have 3 arrays: @arr1=("Furthermore, apigenin treatment increased the level of association of the RNA binding protein HuR with endogenous p53 mRNA","one of the mechanisms by which apigenin induces p53 protein expression is enhancement of translation through the RNA binding protein... (1 Reply)
Discussion started by: vanitham
1 Replies

8. Shell Programming and Scripting

Replacement for eval in Perl??????

I used the eval command in shell programming for assigning a value to a stored value of a variable. Example: VAR="Unix_Id" eval $VAR="101" eval echo $"$VAR" How can i assign a value to a stored value of a variable in perl OR how i can write above code in Perl? I need your help... (4 Replies)
Discussion started by: kunal_dixit
4 Replies

9. Shell Programming and Scripting

Replacement of sed with perl

Hi using the below cmd i am identifying wheether last character in each line in thousands of files as semicolon or not.If last character is semicolon i am removing semicolon .If last character is not semicolon then i am appending next line to present line . For example my input file consists of... (4 Replies)
Discussion started by: dbsurf
4 Replies

10. Shell Programming and Scripting

String Replacement with Perl

I want to replace a string within a file using perl. We have a line that gets commented out, and I want to replace that line now matter how it was commented out. for example, I'd want to replace ###ES=PR1A with ES=PR1A or ##LJW(9/16/26)ES=PR1A with ES=PR1A I tried: perl... (4 Replies)
Discussion started by: Lindarella
4 Replies
Login or Register to Ask a Question