Sponsored Content
Top Forums UNIX for Dummies Questions & Answers extracting selected few lines through perl Post 302213264 by tinivole on Wednesday 9th of July 2008 05:28:51 PM
Old 07-09-2008
a2p and s2p

Hi, so far as I know, there isn't any truly easy way to do this in Perl in quite the same way that awk and sed provides.

But there are two Perl apps that will convert awk and sed code into Perl for you, so you can perhaps learn from them instead.

The first being a2p (awk to perl) and the second being s2p (sed to perl)

To answer one of your example questions, you can emulate "head" in sed with the command:
Code:
sed 10q

So, to convert that into Perl code and save it to a file for reading. The command:
Code:
s2p 10q > head.pl

Would acheive that.

Although, I did say that there isn't any truly easy way in Perl, and you may be quite blown by the output of that command.

Regards
Iain
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

print selected lines

Hi everybody: I try to print in new file selected lines from another file wich depends on the first column. I have done a script like this: lines=( "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "21" "31" "41" "51" "55" "57" "58" ) ${lines} for lines in ${lines} do awk -v ... (6 Replies)
Discussion started by: tonet
6 Replies

2. Shell Programming and Scripting

Sum value from selected lines script (awk,perl)

Hello. I face this (2 side) problem. Some lines with this structure. ........... 12345678 4 12345989 13 12346356 205 12346644 74 12346819 22 ......... The first field (timestamp) is growing (or at least equal). 1)Sum the second fields if the first_field/500 are... (8 Replies)
Discussion started by: paolfili
8 Replies

3. UNIX for Dummies Questions & Answers

Copy selected lines in vim

Hi, I am looking to copy selected lines from a file using the vim editor. I have looked up a few resources and they have suggested to use this- Type mk Type: "ay'k (double quotes, <register name from a-z>, <y-yank single quote, k You can paste those lines wherever you want with "ap I tried... (7 Replies)
Discussion started by: coolavi
7 Replies

4. Shell Programming and Scripting

Process selected lines

I have an if statement where I state that if there are more than one records (lines) found containing a string in a file, then it enters into a while loop to use each line for as many lines as there are and then stop. Trouble is, I can't figure out how to move to the next instance of each line. ... (2 Replies)
Discussion started by: derekphl
2 Replies

5. UNIX for Dummies Questions & Answers

Extracting lines present in one file but missing in another using Perl

Hey I have an input file containing a list of numbers like: U01120.CDS.1 D25328.CDS.1 X15573.CDS.1 K03515.CDS.1 L44140.CDS.10 U24183.CDS.1 M97347.CDS.1 U05259.CDS.1 And another input file containing results created on the basis of the above input: G6PT_HUMAN U01120.CDS.1 -1.9450 3.1706... (1 Reply)
Discussion started by: Banni
1 Replies

6. Shell Programming and Scripting

trying to print selected fields of selected lines by AWK

I am trying to print 1st, 2nd, 13th and 14th fields of a file of line numbers from 29 to 10029. I dont know how to put this in one code. Currently I am removing the selected lines by awk 'NR==29,NR==10029' File1 > File2 and then doing awk '{print $1, $2, $13, $14}' File2 > File3 Can... (3 Replies)
Discussion started by: ananyob
3 Replies

7. Shell Programming and Scripting

finding least out of selected lines

Hello, I have a file, which looks like: I want to print the row containg "PRO" in second column after comparing and finding the minimum value of fifth column present in all "PRO". and likewise for every other string present in second column. I am using : filename=list... (2 Replies)
Discussion started by: CAch
2 Replies

8. Shell Programming and Scripting

AWK script - extracting min and max values from selected lines

Hi guys! I'm new to scripting and I need to write a script in awk. Here is example of file on which I'm working ATOM 4688 HG1 PRO A 322 18.080 59.680 137.020 1.00 0.00 ATOM 4689 HG2 PRO A 322 18.850 61.220 137.010 1.00 0.00 ATOM 4690 CD ... (18 Replies)
Discussion started by: grincz
18 Replies

9. Shell Programming and Scripting

Delete selected lines

hi Gurus, I have a source file with more than 10 columns ( not fixed ) I want to delete all the lines on the following condition 1) where i have first column as "UPDATE PLAN ADD RATE SCHEDULE" and fourth column as null awk '($1=="UPDATE PLAN ADD RATE SCHEDULE" && $4=="") {print $0}'... (5 Replies)
Discussion started by: r_t_1601
5 Replies

10. Shell Programming and Scripting

Selected matching lines

two files: one with the line number only, and the 2nd one with line number and content, as following: line_file.txt 1 3 5 9 23 30 content_file.txt 1|we are the world|good|great 2|easily do this by highlighting you|easily do this by highlighting you|easily do this by highlighting... (2 Replies)
Discussion started by: dtdt
2 Replies
PERL-AFTER-UPGRADE(1)					User Contributed Perl Documentation				     PERL-AFTER-UPGRADE(1)

NAME
perl-after-upgrade -- fixup FreeBSD packages that depend on perl SYNOPSIS
perl-after-upgrade perl-after-upgrade -f perl-after-upgrade -v DESCRIPTION
The standard procedure after a perl port (either lang/perl5.6 or lang/perl5.8) upgrade is to basically reinstall all other packages that depend on perl. This is always a painful exercise. The perl-after-upgrade utility makes this process mostly unnecessary. The tool goes through the list of installed packages, looks for those that depend on perl, moves files around, modifies shebang lines in those scripts in which it is necessary to do so, tries its best to adjust dynamically linked binaries that link with libperl.so in the old path, and updates the package database. After installation of the new perl is complete, either by hand from the ports collection, or from a package, or via portupgrade, do the following: o go root; o run perl-after-upgrade utility. Do not specify any arguments at first, so it does nothing destructive. Pay attention to the produced output and especially to errorlist at the end, if any; o run the utility again, with -f command line option. This will actually do the work. Again, pay attention to the output produced; o fix any reported errors; o reinstall required packages: The utility will tell you what packages that depend on perl it could not handle. It will also tell you why it happened (for example, they were compiled against a binary incompatible perl). If you want such packages to remain operational, you will have to reinstall then by hand or via portupgrade. o review the files left in the older perl installation. This is typically /usr/local/lib/perl5/site_perl/5.X.Y/. There should be very little, if any, files in that directory and its subdi- rectories, excepting a number of .ph files; o check that things work as they should; o remove backup files from the package database. Those will be /var/db/pkg/*/+CONTENTS.bak; o that's all. COPYRIGHT AND LICENSE
Copyright 2005 by Anton Berezin "THE BEER-WARE LICENSE" (Revision 42) <tobez@FreeBSD.org> wrote this module. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. Anton Berezin NO WARRANTY OF ANY KIND, USE AT YOUR OWN RISK. HISTORY
The first version of this utility was not bundled with perl package on FreeBSD. It was dumber than the current version in several impor- tant areas. It was faster. CREDITS
Thanks to Mathieu Arnold for discussion. SEE ALSO
perl(1). perl v5.8.9 2009-04-13 PERL-AFTER-UPGRADE(1)
All times are GMT -4. The time now is 03:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy