Sponsored Content
Top Forums UNIX for Beginners Questions & Answers awk unable to print array next to each other Post 303045776 by RudiC on Monday 13th of April 2020 05:08:45 AM
Old 04-13-2020
Quote:
Originally Posted by shanul karim
.
.
.

From above description i got the idea in general.
Fine. But: You should try to get a more profound understanding.

Quote:
But if you can explain code line by line.. I mean each variable and method.

.
.
.
I don't feel this is a good approach. It would be better you check each line, variable and method yourself with the help of e.g. man awk and e.g. printing out intermediate steps / variables like COLN[i], OUT, or TMP. If you really, really get stuck with a statement or result, post back very specifically, and people may jump in.


This may seem tedious on first sight, but will be rewarding in the long run.







Quote:
Originally Posted by shanul karim
Dear RudC,


Can we have changes in your script according to below data..

Can almost certainly be done, but the input file changed profoundly: I can't tell where and how fields / values are separated; it seems all just a looong unstructured string. So, the script / logics may need to be turned upside down. On top, some fields / characters ( ; , final " ) seem missing...

Last edited by RudiC; 04-13-2020 at 06:17 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to set a data to array

Hi All, Iam trying to set the value to the array... Still its not happening Following is the code: #!/usr/bin/ksh filenames="x"; filenames="y"; echo $filenames; echo $filenames; O/P: x x Iam expecting (2 Replies)
Discussion started by: kiranlalka
2 Replies

2. Solaris

Unable to access 3500 FC array. Where is the problem?..

Hi, I have two Sun Fire V490 with Solaris 10 5/08, FC switch and two Sun StorageTek 3500 FC arrays. Each array is connected to switch and to one server at a time. In the last week I installed Solaris 10 5/08 on both servers and set up Sun Cluster, version 3.2. At wednesday all was fine - all... (7 Replies)
Discussion started by: Sapfeer
7 Replies

3. Shell Programming and Scripting

awk: reading into an array and then print the value corresponding to index

I am beginner in awk awk 'BEGIN{for(i=1;(getline<"opnoise")>0;i++) arr=$1}{print arr}' In the above script, opnoise is a file, I am reading it into an array and then printing the value corresponding to index 20. Well this is not my real objective, but I have posted this example to describe... (19 Replies)
Discussion started by: akshaykr2
19 Replies

4. Shell Programming and Scripting

Print array into a single file - AWK

Hi all, I been looking for a solution to the fact that when I use: for (i=1; i<=NF; i++) print $ifields that are originally in a single line are printed in a single line I have severals files for which the first 7 are the same, but the number of variables after that can vary, for example NF... (5 Replies)
Discussion started by: PaulaL
5 Replies

5. Programming

Unable to assign zero to unsigned character array

Hi, I am unable to assign value zero to my variable which is defined as unsigned char. typedef struct ABCD { unsigned char abc; unsigned char def; unsigned char ghi; } ABCD; typedef ABCD *PABCD; In my Por*C code, i assign the values using memcpy like below ... (3 Replies)
Discussion started by: gthangav
3 Replies

6. Shell Programming and Scripting

Unable To access array in awk

Hi, i have the following code in which i am passing array tldn in awk using -v option & despite of that condition is not getting matched,can somebody suggest how to handle shell arrays in awk tcount=(9875 9667) awk -F"\t" -v ltldn="${tldn}" 'NR==FNR {POSTPAIDMDNS=$2"|"$3;next} ... (6 Replies)
Discussion started by: siramitsharma
6 Replies

7. UNIX for Dummies Questions & Answers

How To Print Array in awk?

Hello, May i please know how do i print the array using awk script. I am using below shell script to start with but not working. #!/bin/bash LOADSTATUS="Line 0" LOADSTATUS="Line 1" LOADSTATUS="Line 2" LOADSTATUS="Line 3" LOADSTATUS="Line 4" awk ' BEGIN { Your File Load Status }... (1 Reply)
Discussion started by: Ariean
1 Replies

8. Shell Programming and Scripting

Not getting array in .awk file and print it

I have test.sh file as below : set -A IDARR $ID echo | awk -f test.awk -v TempArr="${IDARR }" I have test.awk file as below : BEGIN { Flag = 1; } { print "Hello"; for(i in TempArr) { print i; } } (9 Replies)
Discussion started by: nes
9 Replies

9. Shell Programming and Scripting

awk to print array that occurs the most with matching value in another field

In the below awk I am splitting $7 on the : and then counting each line or NM_xxxx. If the $1 value is the same for each line then print the $7 that occurs the most with the matching $1 value. The awk seems close but I am not sure what is going on. I included a description as well as to what I... (1 Reply)
Discussion started by: cmccabe
1 Replies

10. Shell Programming and Scripting

Unable to print python array in shell script loop.

I am unable to loop print a python string array in my unix shell script: ~/readarr.sh '{{ myarr }}' more readarr.sh echo "Parameter 1:"$1 MYARRAY= $1 IFS= MYARRAY=`python <<< "print ' '.join($MYARRAY)"` for a in "$MYARRAY"; do echo "Printing Array: $a" done Can you... (10 Replies)
Discussion started by: mohtashims
10 Replies
btparse::doc::bt_language(3)					      btparse					      btparse::doc::bt_language(3)

NAME
bt_language - the BibTeX data language, as recognized by btparse SYNOPSIS
# Lexical grammar, mode 1: top-level AT @ NEWLINE COMMENT \%~[ ]* WHITESPACE [ ]+ JUNK ~[@ ]+ # Lexical grammar, mode 2: in-entry NEWLINE COMMENT \%~[ ]* WHITESPACE [ ]+ NUMBER [0-9]+ NAME [a-z0-9!$&*+-./:;<>?[]^\_`|]+ LBRACE { RBRACE } LPAREN ( RPAREN ) EQUALS = HASH # COMMA , QUOTE " # Lexical grammar, mode 3: strings # (very hairy -- see text) # Syntactic grammar: bibfile : ( entry )* entry : AT NAME body body : STRING # for comment entries | ENTRY_OPEN contents ENTRY_CLOSE contents : ( NAME | NUMBER ) COMMA fields # for regular entries | fields # for macro definition entries | value # for preamble entries fields : field { COMMA fields } | field : NAME EQUALS value value : simple_value ( HASH simple_value )* simple_value : STRING | NUMBER | NAME DESCRIPTION
One of the problems with BibTeX is that there is no formal specification of the language. This means that users exploring the arcane corners of the language are largely on their own, and programmers implementing their own parsers are completely on their own---except for observing the behaviour of the original implementation. Other parser implementors (Nelson Beebe of "bibclean" fame, in particular) have taken the trouble to explain the language accepted by their parser, and in that spirit the following is presented. If you are unfamiliar with the arcana of regular and context-free languages, you will not have any easy time understanding this. This is not an introduction to the BibTeX language; any LaTeX book would be more suitable for learning the data language itself. LEXICAL GRAMMAR
The lexical scanner has three distinct modes: top-level, in-entry, and string. Roughly speaking, top-level is the initial mode; we enter in-entry mode on seeing an "@" at top-level; and on seeing the "}" or ")" that ends the entry, we return to top-level. We enter string mode on seeing a """ or non-entry-delimiting "{" from in-entry mode. Note that the lexical language is both non-regular (because braces must balance) and context-sensitive (because "{" can mean different things depending on its syntactic context). That said, we will use regular expressions to describe the lexical elements, because they are the starting point used by the lexical scanner itself. The rest of the lexical grammar will be informally explained in the text. From top-level, the following tokens are recognized according to the regular expressions on the right: AT @ NEWLINE COMMENT \%~[ ]* WHITESPACE [ ]+ JUNK ~[@ ]+ (Note that this is PCCTS regular expression syntax, which should be fairly familiar to users of other regex engines. One oddity is that a character class is negated as "~[...]" rather than "[^...]".) On seeing "at" at top-level, we enter in-entry mode. Whitespace, junk, newlines, and comments are all skipped, with the latter two incrementing a line counter. (Junk is explicitly recognized to allow for "bibtex"'s "implicit comment" scheme.) From in-entry mode, we recognize newline, comment, and whitespace identically to top-level mode. In addition, the following tokens are recognized: NUMBER [0-9]+ NAME [a-z0-9!$&*+-./:;<>?[]^\_`|]+ LBRACE { RBRACE } LPAREN ( RPAREN ) EQUALS = HASH # COMMA , QUOTE " At this point, the lexical scanner starts to sound suspiciously like a context-free grammar, rather than a collection of independent regular expressions. However, it is necessary to keep this complexity in the scanner because certain characters ("{" and "(" in particular) have very different lexical meanings depending on the tokens that have preceded them in the input stream. In particular, "{" and "(" are treated as "entry openers" if they follow one "at" and one "name" token, unless the value of the "name" token is "comment". (Note the switch from top-level to in-entry between the two tokens.) In the @comment case, the delimiter is considered as starting a string, and we enter string mode. Otherwise, the delimiter is saved, and when we see a corresponding "}" or ")" it is considered an "entry closer". (Braces are balanced for free here because the string lexer takes care of counting brace-depth.) Anywhere else, "{" is considered as starting a string, and we enter string mode. """ always starts a string, regardless of context. The other tokens ("name", "number", "equals", "hash", and "comma") are recognized unconditionally. Note that "name" is a catch-all token used for entry types, citation keys, field names, and macro names; because BibTeX has slightly different (largely undocumented) rules for these various elements, a bit of trickery is needed to make things work. As a starting point, consider BibTeX's definition of what's allowed for an entry key: a sequence of any characters except " # % ' ( ) , = { } plus space. There are a couple of problems with this scheme. First, without specifying the character set from which those "magic 10" characters are drawn, it's a bit hard to know just what is allowed. Second, allowing "@" characters could lead to confusing BibTeX syntax (it doesn't confuse BibTeX, but it might confuse a human reader). Finally, allowing certain characters that are special to TeX means that BibTeX can generate bogus TeX code: try putting a backslash ("") or tilde ("~") in a citation key. (This last exception is rather specific to the "generating (La)TeX code from a BibTeX database" application, but since that's the major application for BibTeX databases, then it will presumably be the major application for btparse, at least initially. Thus, it makes sense to pay attention to this problem.) In btparse, then, a name is defined as any sequence of letters, digits, underscores, and the following characters: ! $ & * + - . / : ; < > ? [ ] ^ _ ` | This list was derived by removing BibTeX's "magic 10" from the set of printable 7-bit ASCII characters (32-126), and then further removing "@", "", and "~". This means that btparse disallows some of the weirder entry keys that BibTeX would accept, such as "foo@bar", but still allows a string with initial digits. In fact, from the above definition it appears that btparse would accept a string of all digits as a "name;" this is not the case, though, as the lexical scanner recognizes such a digit string as a number first. There are two problems here: BibTeX entry keys may in fact be entirely numeric, and field names may not begin with a digit. (Those are two of the not-so-obvious differences in BibTeX's handling of keys and field names.) The tricks used to deal with these problems are implemented in the parser rather than the lexical scanner, so are described in "SYNTACTIC GRAMMAR" below. The string lexer recognizes "lbrace", "rbrace", "lparen", and "rparen" tokens in order to count brace- or parenthesis-depth. This is necessary so it knows when to accept a string delimited by braces or parentheses. (Note that a parenthesis-delimited string is only allowed after @comment---this is not a normal BibTeX construct.) In addition, it converts each non-space whitespace character (newline, carriage-return, and tab) to a single space. (Sequences of whitespace are not collapsed; that's the domain of string post-processing, which is well removed from the scanner or parser.) Finally, it accepts """ to delimit quote-delimited strings. Apart from those restrictions, the string lexer accepts anything up to the end-of-string delimiter. SYNTACTIC GRAMMAR
(The language used to describe the grammar here is the extended Backus-Naur Form (EBNF) used by PCCTS. Terminals are represented by uppercase strings, non-terminals by lowercase strings; terminal names are the same as those given in the lexical grammar above. "( foo )*" means zero or more repetitions of the "foo" production, and "{ foo }" means an optional "foo".) A file is just a sequence of zero or more entries: bibfile : ( entry )* An entry is an at-sign, a name (the "entry type"), and the entry body: entry : AT NAME body A body is either a string (this alternative is only tried if the entry type is "comment") or the entry contents: body : STRING # for comment entries | ENTRY_OPEN contents ENTRY_CLOSE ("ENTRY_OPEN" and "ENTRY_CLOSE" are either "{" and "}" or "(" and ")", depending what is seen in the input for a particular entry.) There are three possible productions for the "contents" non-terminal. Only one applies to any given entry, depending on the entry metatype (which in turn depends on the entry type). Currently, btparse supports four entry metatypes: comment, preamble, macro definition, and regular. The first two correspond to @comment and @preamble entries; "macro definition" is for @string entries; and "regular" is for all other entry types. (The library will be extended to handle @modify and @alias entry types, and corresponding "modify" and "alias" metatypes, when BibTeX 1.0 is released and the exact syntax is known.) The "metatype" concept is necessary so that all entry types that aren't specifically recognized fall into the "regular" metatype. It's also convenient not to have to "strcmp" the entry type all the time. contents : ( NAME | NUMBER ) COMMA fields # for regular entries | fields # for macro definition entries | value # for preamble entries Note that the entry key is not just a "NAME", but "( NAME | NUMBER)". This is necessary because BibTeX allows all-numeric entry keys, but btparse's lexical scanner recognizes such digit strings as "NUMBER" tokens. "fields" is a comma-separated list of fields, with an optional single trailing comma: fields : field { COMMA fields } | A "field" is a single "field = value" assignment: field : NAME EQUALS value Note that "NAME" here is a restricted version of the "name" token described in "LEXICAL GRAMMAR" above. Any "name" token will be accepted by the parser, but it is immediately checked to ensure that it doesn't begin with a digit; if so, an artificial syntax error is triggered. (This is for compatibility with BibTeX, which doesn't allow field names to start with a digit.) A "value" is a series of simple values joined by '#' characters: value : simple_value ( HASH simple_value )* A simple value is a string, number, or name (for macro invocations): simple_value : STRING | NUMBER | NAME SEE ALSO
btparse AUTHOR
Greg Ward <gward@python.net> btparse, version 0.63 2012-06-02 btparse::doc::bt_language(3)
All times are GMT -4. The time now is 01:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy