Sponsored Content
Top Forums UNIX for Beginners Questions & Answers awk Associative Array and/or Referring to Field by String (Nonconstant String Value) Post 303030018 by jvoot on Monday 4th of February 2019 03:16:43 PM
Old 02-04-2019
Quote:
Originally Posted by RudiC
It does. Please apply what has been said to the repective line:
Code:
 PS028,006 [KJ <Cj>] [CM< <Pr>] [QWL TXNWNJ- <Ob>]
^          ^       ^ ^        ^ ^                ^--- last separator; $NF is empty
|          +-------+-+--------+-+-------------------- all FS
+---------------------------------------------------- field 1

Is that clearer now? If you want to remove the leading space from field 1, additional measures must be taken.
OK, thank you so much. I was under the impression that the field separator value was set to the *string* "][" rather than "]" or "[", thus I thought that $1 in the code would have been PS028,006 [KJ <Cj>, rather than PS028,006. This was very helpful. Thank you for taking the time to explain this.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with lookup values on AWK associative array

I'm at wits end with this issue and my troubleshooting leads me to believe it is a problem with the file formatting of the array referenced by my script: awk -F, '{if (NR==FNR) {a=$4","$3","$2}\ else {print a "," $0}}' WBTSassignments1.txt RNCalarms.tmp On the WBTSassignments1.txt file... (2 Replies)
Discussion started by: JasonHamm
2 Replies

2. Shell Programming and Scripting

Awk Search text string in field, not all in field.

Hello, I am using awk to match text in a tab separated field and am able to do so when matching the exact word. My problem is that I would like to match any sequence of text in the tab-separated field without having to match it all. Any help will be appreciated. Please see the code below. awk... (3 Replies)
Discussion started by: rocket_dog
3 Replies

3. Shell Programming and Scripting

awk, associative array, compare files

i have a file like this < '393200103052';'H3G';'20081204' < '393200103059';'TIM';'20110111' < '393200103061';'TIM';'20060206' < '393200103064';'OPI';'20110623' > '393200103052';'HKG';'20081204' > '393200103056';'TIM';'20110111' > '393200103088';'TIM';'20060206' Now i have to generate a file... (9 Replies)
Discussion started by: shruthi123
9 Replies

4. Homework & Coursework Questions

passing letters from an array into a string for string comparison

attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now. ##I have an array $wordString that initializes to a string of dashes ##reflecting the number of letters in $theWord ##every time the user enters a (valid)... (5 Replies)
Discussion started by: lotsofideas
5 Replies

5. Shell Programming and Scripting

Help needed on Associative array in awk

Hi All, I got stuck up with shell script where i use awk. The scenario which i am working on is as below. I have a file text.txt with contents COL1 COL2 COL3 COL4 1 A 500 400 1 B 500 400 1 A 500 200 2 A 290 300 2 B 290 280 3 C 100 100 I could able to sum col 3 and col4 based on... (3 Replies)
Discussion started by: imsularif
3 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. Shell Programming and Scripting

Split string into map (Associative Array)

Hi Input: { committed = 782958592; init = 805306368; max = 1051394048; used = 63456712; } Result: A map (maybe Associative Array) where I can iterate through the key/value. Something like this: for key in $map do echo key=$key value=$map done Sample output from the map: ... (2 Replies)
Discussion started by: chitech
2 Replies

8. Shell Programming and Scripting

Awk: Dealing with whitespace in associative array indicies

Is there a reliable way to deal with whitespace in array indicies? I am trying to annotate fails in a database using a table of known fails. In a begin block I have code like this: # Read in Known Fail List getline < "'"$failListFile"'"; getline < "'"$failListFile"'"; getline <... (6 Replies)
Discussion started by: Michael Stora
6 Replies

9. UNIX for Beginners Questions & Answers

String has * as the field delimiter and I need echo/awk to escape it, how?

Hi, I am trying to read an Oracle listener log file line by line and need to separate the lines into several fields. The field delimiter for the line happens to be an asterisk. I have the script below to start with but when running it, the echo command is globbing it to include other... (13 Replies)
Discussion started by: newbie_01
13 Replies

10. Shell Programming and Scripting

awk to average field if matching string in another

In the awk below I am trying to get the average of the sum of $7 if the string in $4 matches in the line below it. The --- in the desired out is not needed, it is just to illustrate the calculation. The awk executes and produces the current out. I am not sure why the middle line is skipped and the... (2 Replies)
Discussion started by: cmccabe
2 Replies
PPI::Statement::Include(3)				User Contributed Perl Documentation				PPI::Statement::Include(3)

NAME
PPI::Statement::Include - Statements that include other code SYNOPSIS
# The following are all includes use 5.006; use strict; use My::Module; use constant FOO => 'Foo'; require Foo::Bar; require "Foo/Bar.pm"; require $foo if 1; no strict 'refs'; INHERITANCE
PPI::Statement::Include isa PPI::Statement isa PPI::Node isa PPI::Element DESCRIPTION
Despite its name, the "PPI::Statement::Include" class covers a number of different types of statement that cover all statements starting with "use", "no" and "require". But basically, they cover three situations. Firstly, a dependency on a particular version of perl (for which the "version" method returns true), a pragma (for which the "pragma" method returns true, or the loading (and unloading via no) of modules. METHODS
"PPI::Statement::Include" has a number of methods in addition to the standard PPI::Statement, PPI::Node and PPI::Element methods. type The "type" method returns the general type of statement ('use', 'no' or 'require'). Returns the type as a string, or "undef" if the type cannot be detected. module The "module" method returns the module name specified in any include statement. This "includes" pragma names, because pragma are implemented as modules. (And lets face it, the definition of a pragma can be fuzzy at the best of times in any case) This covers all of these... use strict; use My::Module; no strict; require My::Module; ...but does not cover any of these... use 5.006; require 5.005; require "explicit/file/name.pl"; Returns the module name as a string, or "undef" if the include does not specify a module name. module_version The "module_version" method returns the minimum version of the module required by the statement, if there is one. pragma The "pragma" method checks for an include statement's use as a pragma, and returns it if so. Or at least, it claims to. In practice it's a lot harder to say exactly what is or isn't a pragma, because the definition is fuzzy. The "intent" of a pragma is to modify the way in which the parser works. This is done though the use of modules that do various types of internals magic. For now, PPI assumes that any "module name" that is only a set of lowercase letters (and perhaps numbers, like "use utf8;"). This behaviour is expected to change, most likely to something that knows the specific names of the various "pragmas". Returns the name of the pragma, or false ('') if the include is not a pragma. version The "version" method checks for an include statement that introduces a dependency on the version of "perl" the code is compatible with. This covers two specific statements. use 5.006; require 5.006; Currently the version is returned as a string, although in future the version may be returned as a version object. If you want a numeric representation, use "version_literal()". Returns false if the statement is not a version dependency. version_literal The "version_literal" method has the same behavior as "version()", but the version is returned as a numeric literal. Returns false if the statement is not a version dependency. The "arguments" method gives you the rest of the statement after the the module/pragma and module version, i.e. the stuff that will be used to construct what gets passed to the module's "import()" subroutine. This does include the comma, etc. operators, but doesn't include non- significant direct children or any final semicolon. TO DO
- Write specific unit tests for this package SUPPORT
See the support section in the main module. AUTHOR
Adam Kennedy <adamk@cpan.org> COPYRIGHT
Copyright 2001 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.18.2 2011-02-25 PPI::Statement::Include(3)
All times are GMT -4. The time now is 01:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy