Sponsored Content
Top Forums Shell Programming and Scripting Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line? Post 302998439 by durden_tyler on Thursday 1st of June 2017 03:18:14 PM
Old 06-01-2017
Also check the eof and eof() functions in the Perl documentation.
The eof function can be used to reset the line number in case multiple files are fed to the perl interpreter.

Code:
 $
$ cat -n file1.dat
     1  Data in line 1 of file file_1.dat
     2  Data in line 2 of file file_1.dat
     3  Data in line 3 of file file_1.dat
     4  Data in line 4 of file file_1.dat
     5  Data in line 5 of file file_1.dat
$
$ cat -n file2.dat
     1  Data in line 1 of file file_2.dat
     2  Data in line 2 of file file_2.dat
     3  Data in line 3 of file file_2.dat
     4  Data in line 4 of file file_2.dat
     5  Data in line 5 of file file_2.dat
$
$ cat -n file3.dat
     1  Data in line 1 of file file_3.dat
     2  Data in line 2 of file file_3.dat
     3  Data in line 3 of file file_3.dat
     4  Data in line 4 of file file_3.dat
     5  Data in line 5 of file file_3.dat
$
$ # $. is not reset by itself. Perl numbers the pseudo-file formed from the files listed on the command line
$ perl -lne 'printf("File = %s, Line = %2d : [%s]\n", $ARGV, $., $_)' file1.dat file2.dat file3.dat
File = file1.dat, Line =  1 : [Data in line 1 of file file_1.dat]
File = file1.dat, Line =  2 : [Data in line 2 of file file_1.dat]
File = file1.dat, Line =  3 : [Data in line 3 of file file_1.dat]
File = file1.dat, Line =  4 : [Data in line 4 of file file_1.dat]
File = file1.dat, Line =  5 : [Data in line 5 of file file_1.dat]
File = file2.dat, Line =  6 : [Data in line 1 of file file_2.dat]
File = file2.dat, Line =  7 : [Data in line 2 of file file_2.dat]
File = file2.dat, Line =  8 : [Data in line 3 of file file_2.dat]
File = file2.dat, Line =  9 : [Data in line 4 of file file_2.dat]
File = file2.dat, Line = 10 : [Data in line 5 of file file_2.dat]
File = file3.dat, Line = 11 : [Data in line 1 of file file_3.dat]
File = file3.dat, Line = 12 : [Data in line 2 of file file_3.dat]
File = file3.dat, Line = 13 : [Data in line 3 of file file_3.dat]
File = file3.dat, Line = 14 : [Data in line 4 of file file_3.dat]
File = file3.dat, Line = 15 : [Data in line 5 of file file_3.dat]
$
$ # $. is reset for each file; similar to awk's FNR == NR idiom
$ perl -lne 'printf("File = %s, Line = %2d : [%s]\n", $ARGV, $., $_); close(ARGV) if eof' file1.dat file2.dat file3.dat
File = file1.dat, Line =  1 : [Data in line 1 of file file_1.dat]
File = file1.dat, Line =  2 : [Data in line 2 of file file_1.dat]
File = file1.dat, Line =  3 : [Data in line 3 of file file_1.dat]
File = file1.dat, Line =  4 : [Data in line 4 of file file_1.dat]
File = file1.dat, Line =  5 : [Data in line 5 of file file_1.dat]
File = file2.dat, Line =  1 : [Data in line 1 of file file_2.dat]
File = file2.dat, Line =  2 : [Data in line 2 of file file_2.dat]
File = file2.dat, Line =  3 : [Data in line 3 of file file_2.dat]
File = file2.dat, Line =  4 : [Data in line 4 of file file_2.dat]
File = file2.dat, Line =  5 : [Data in line 5 of file file_2.dat]
File = file3.dat, Line =  1 : [Data in line 1 of file file_3.dat]
File = file3.dat, Line =  2 : [Data in line 2 of file file_3.dat]
File = file3.dat, Line =  3 : [Data in line 3 of file file_3.dat]
File = file3.dat, Line =  4 : [Data in line 4 of file file_3.dat]
File = file3.dat, Line =  5 : [Data in line 5 of file file_3.dat]
$
$

 

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Command line tool to join multiple .wmv files?

I need a simple command line executable that allows me to join many wmv files into one output wmv file, preferrably in a simple way like this: wmvjoin file1.wmv file2.wmv .... > outputfile.wmv So what I want is the wmv-equivalent of mpgtx I cannot find it on internet. Thanks. (2 Replies)
Discussion started by: karman
2 Replies

2. Shell Programming and Scripting

Need the line to be printed in single line

Hi, I have my code like this v_site_eli=`sqlplus -s<<-EOsqlplus $SQL_USERNAME/$SQL_PASSWD WHENEVER SQLERROR EXIT SQL.SQLCODE WHENEVER OSERROR EXIT FAILURE SET TERM OFF SET HEAD OFF SET VERIFY OFF SET FEEDBACK OFF declare VARIABLE vn_return_sts varchaR2(6); begin SELECT... (1 Reply)
Discussion started by: mjkreddy
1 Replies

3. Shell Programming and Scripting

Perl, searching multiple files and printing returned line to new file

I am trying to find a way to utilise the full potential of my cpu cores and memory on my windows machine. Now, I am quite familiar with grep, however, running a Unix based OS is not an option right now. Unfortunately, the 32 bit grep for windows that I am running, I cannot run multiple... (1 Reply)
Discussion started by: Moloch
1 Replies

4. Shell Programming and Scripting

perl script command line option driven script

could someone show me a sample command line option driven script? i want to see an easy way to write one and how i can execute it using command line options such as typing in read.pl -i <id> -c <cmds> -s <start> -e <end> would read out all the commands run by ID . from start time to... (7 Replies)
Discussion started by: kpddong
7 Replies

5. Homework & Coursework Questions

trouble understanding file option and command line arguments

Hi, I am creating a program with the C language that simulates the WC command in Unix. My program needs to count lines, bytes and words. I have not added the code to count bytes and words yet. I am having trouble understanding what the file option/flag '-' does. I can not visualize how it moves... (1 Reply)
Discussion started by: heywoodfloyd
1 Replies

6. Shell Programming and Scripting

FAQ how to download multiple specific files via command line

Hi, This evening i would like to download multiple pcap captures files in the wireshark wiki sites. My aim is to download the capture files .pcap .cap and etc on the wireshark site SampleCaptures - The Wireshark Wiki. i already used wget, lynx, htget but still their problem downloading..it seems... (1 Reply)
Discussion started by: jao_madn
1 Replies

7. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

8. Shell Programming and Scripting

Perl how to compare two pdf files line by line

Hi Experts, Would really appreciate if anyone can guide me how to compare two pdf files line by line and report the difference to another file. (3 Replies)
Discussion started by: prasanth_babu
3 Replies

9. Shell Programming and Scripting

Perl : accept multiple user entered command line arguemnts

I am trying to create a script that will accept multi input from the user (really just me), then execute those command on a remote device. My question is if the I enter "No" at the confirmation point "Are these statements correct y or n ?", what is the best way to go back and start over ? I... (3 Replies)
Discussion started by: popeye
3 Replies

10. UNIX for Dummies Questions & Answers

How to get " printed on command line?

Hey, Is there a way I can print " in a command line? When I type "echo "set variable = disco"".... This actually prints echo set variable = disco but I would like to print it out as --- echo "set variable = disco" Thanks, Satya (4 Replies)
Discussion started by: Indra2011
4 Replies
geom(1) 																   geom(1)

NAME
geom - analyzes a molecular geometry input in Cartesian coordinates. DESCRIPTION
The program geom reads a set of Cartesian coordinates and determines from them the bond distances (Bohr and angstrom), bond angles, tor- sional angles, out-of-plane angles (optional), moments of inertia, and rotational constants. FILES REQUIRED
input.dat - Input file and one of the following: geom.dat - geometry file file11.dat - PSI-format geometry/gradient file FILES GENERATED
geom.out - file containing the analysis INPUT OPTIONS
The geom program has the following options: -h Print help information (these options). -aces [filename] Read the input in an ACES output format, with each line consisting of atomic symbol, atomic number, and Cartesian coordinates (in Bohr). The optional argument is the name of the geometry input file, which defaults to geom.dat. -qchem [filename] Read the input in an QCHEM output format, with each line consisting of the atom number, the atomic symbol, and Cartesian coordinates (in Angstroms). The optional argument is the name of the geometry input file, which defaults to geom.dat. -xyz [filename] Read the input in an XYZ output format. The first line contains the number of atoms and the second line is a comment line. Subse- quent lines each contain the atomic symbol and Cartesian X Y and Z coordinates (in Angstroms). The optional argument is the name of the geometry input file, which defaults to geom.dat. -oop Print out-of-plane angles, where the angle a-b-c-d is defined as the angle formed by the vector a-d and the plane defined by atoms b, c, and d. DO_OOP = boolean Same as command-line switch -oop described above. ISOTOPES = matrix of reals/strings Used to specify masses to be used in the calculation of the center of mass and rotational constants. One array is provided for each isotopomer to be calculated. The arrays can mix floating point numbers with strings which designate isotopes. If this array is not given and file11.dat is present, then the masses will be obtained by converting the atomic numbers in file11. If masses are not given by ISOTOPES or by file11, then no mass-related quantities will be calculated. -g [filename] Read Cartesian coordinates from a file other than file11.dat. If a filename is not given, the default is geom.dat. The alternative file is assumed to be in a format similar to that of PSI's geom.dat. Since such files do not contain atomic numbers, the moments of inertia and rotational constants are not calculated if this option is used. READ_GEOM = boolean This option in input.dat tells geom to read the geometry from geom.dat in the PSI geom.dat format. -a Print parameters for all pair distances. PRINT_ALL_DIST = boolean Same as -a flag described above. -d distance Only print parameters involving pairs of atoms which are less than distance bohr apart (default value is 4.0 bohr). PRINT_DISTANCE = value Same as -d flag described above. -angstrom The input coordinates are in angstroms, not bohr. ANGSTROM = boolean If TRUE, the input coordinates are in angstroms instead of bohr. The default is FALSE. The following example is for calculating the geometrical information for water with several different isotopes. The geometry is read from geom.dat rather than from file11.dat. geom: ( read_geom = true isotopes = ( (O H H) (O D D) (O18 1.007825 1.007825) ) ) 5 June, 1998 geom(1)
All times are GMT -4. The time now is 10:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy