I have example config file with two arrays:
and csv file:
is it possible to pass those arrays to awk and print (redirect to another file) only those records where
1. fields 2 and 3 match to any element from tab1
AND
2. field 12 match to any element from tab2
?
Now I am planning my script but so far my only idea is to run two loops (pseudo-code):
I will be gratful for any advise/ideas or links which can help me.
Hi All,
I have been working on awk and arrays. I have this small script:
cat maillog*|awk -F: '$2=="SMTP-Accept" && $5~/string/ {lastdate=substr($1,1,8); internaluser=$5; v++} END {for (j in v) {print lastdate, v, j}'| sort>> mail.list
This gives me the number of mails users are getting. ... (1 Reply)
Guys,
OK so i have been trying figure this all all day, i guess its a pretty easy way to do it.
Right, so i have to column of data which i have gotten from one huge piece of data. What i would like to do is to put both of these into one array using awk. Is this possible??
If so could... (1 Reply)
Hi, I've written the following code to manipulate the first 40 lines of a data file into my desired order:
#!/bin/awk -f
{ if (NR<=(4)){
a=a$0" "}
else { if ((NR >= (5)) && (NR <= (13))) {
b=b$0" " }
else {if ((NR >= (14)) && (NR <= (25))){
c=c$0" "}
... (5 Replies)
Hi
I'm not a programmer but am muddling through as best I can. I am trying to set up a PostSearchHook for Radiator (RADIUS server), that carries out an LDAP lookup, and, based on the
string returned ("staff" or "student") in the "businessCategory" attribute, will set the $role to be either 40... (3 Replies)
Hi,
I have spent the afternoon trawling Google, Unix.com and Unix in a Nutshell for information on how awk arrays work, and I'm not really getting too far.
I ahve a batch of code that I am pretty sure can be better managed using awk, but I'm not sure how to use awk arrays to do what I'm... (1 Reply)
Hi to all,
I write this time to ask for different syntax or ways of arrays within awk and uses.
Since I don't know how actually could work and the real potencial of awk arrays, I look for a proactive reply/help in order to get
more information than it seems I'm trying to get.
I think I... (2 Replies)
Hi
Can someone please explain the logic of awk arrays. I have been doing some reading but I dont understand this:
#!/usr/bin/gawk -f
{
arr++;
}
end
{
for(i in arr)
{
print arr,i
}
}
As I understand arr refs the arrays index, so while $2 is a string that cant... (2 Replies)
Hi, buddies
I am new to shell scripting and trying to solve a problem. I read about arrays in awk that they are quite powerful and are associative in nature.
Awk Gurus Please help!
I have a file:
Id1 pp1 0t4 pp8 xy2
Id43 009y black
Id6 red xy2
Id12 new pp1 black
I have... (5 Replies)
So I'm back once again beating my head off a wall trying to figure out how to get this to work.
My end goal is to take input such as what's below, which will be capture in real time with a tail -f from a file or piped output from another command:
... (5 Replies)
Array A contains lines of numbers from files. Array B contains number of fields for each line of each file.
I want to run on array A. To do that I need to know the number of fields for each file in array A (because each line doesn't have the same NF).
The NF is in array B, problem is: I don't... (6 Replies)
Discussion started by: guitarist684
6 Replies
LEARN ABOUT OPENSOLARIS
expand
expand(1) User Commands expand(1)NAME
expand, unexpand - expand TAB characters to SPACE characters, and vice versa
SYNOPSIS
expand [-t tablist] [file]...
expand [-tabstop] [-tab1, tab2,. . ., tabn] [file]...
unexpand [-a] [-t tablist] [file]...
DESCRIPTION
The expand utility copies files (or the standard input) to the standard output, with TAB characters expanded to SPACE characters. BACKSPACE
characters are preserved into the output and decrement the column count for TAB calculations. expand is useful for pre-processing character
files (before sorting, looking at specific columns, and so forth) that contain TAB characters.
unexpand copies files (or the standard input) to the standard output, putting TAB characters back into the data. By default, only leading
SPACE and TAB characters are converted to strings of tabs, but this can be overridden by the -a option (see the OPTIONS section below).
OPTIONS
The following options are supported for expand:
-t tablist Specifies the tab stops. The argument tablist must consist of a single positive decimal integer or multiple posi-
tive decimal integers, separated by blank characters or commas, in ascending order. If a single number is given,
tabs will be set tablist column positions apart instead of the default 8. If multiple numbers are given, the tabs
will be set at those specific column positions.
Each tab-stop position N must be an integer value greater than zero, and the list must be in strictly ascending
order. This is taken to mean that, from the start of a line of output, tabbing to position N causes the next
character output to be in the (N+1)th column position on that line.
In the event of expand having to process a tab character at a position beyond the last of those specified in a
multiple tab-stop list, the tab character is replaced by a single space character in the output.
-tabstop Specifies as a single argument, sets TAB characters tabstop SPACE characters apart instead of the default 8.
-tab1,tab2,...,tabn Sets TAB characters at the columns specified by -tab1,tab2,...,tabn
The following options are supported for unexpand:
-a Inserts TAB characters when replacing a run of two or more SPACE characters would produce a smaller output file.
-t tablist Specifies the tab stops. The option-argument tablist must be a single argument consisting of a single positive decimal inte-
ger or multiple positive decimal integers, separated by blank characters or commas, in ascending order. If a single number
is given, tabs will be set tablist column positions apart instead of the default 8. If multiple numbers are given, the tabs
will be set at those specific column positions. Each tab-stop position N must be an integer value greater than zero, and the
list must be in strictly ascending order. This is taken to mean that, from the start of a line of output, tabbing to posi-
tion N will cause the next character output to be in the (N+1)th column position on that line. When the -t option is not
specified, the default is the equivalent of specifying -t 8 (except for the interaction with -a, described below).
No space-to-tab character conversions occur for characters at positions beyond the last of those specified in a multiple
tab-stop list.
When -t is specified, the presence or absence of the -a option is ignored; conversion will not be limited to the processing
of leading blank characters.
OPERANDS
The following ooperand is supported for expand and unexpand:
file The path name of a text file to be used as input.
ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of expand and unexpand: LANG, LC_ALL,
LC_CTYPE, LC_MESSAGES, and NLSPATH.
EXIT STATUS
The following exit values are returned:
0 Successful completion
>0 An error occurred.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWesu |
+-----------------------------+-----------------------------+
|CSI |enabled |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
SEE ALSO tabs(1), attributes(5), environ(5), standards(5)SunOS 5.11 1 Feb 1995 expand(1)