Questions tagged [nawk]

`nawk` is a pattern scanning and processing language.

A nawk program is a sequence of patterns and corresponding actions.

The string specifying program must be enclosed in single quotes (') to protect it from interpretation by the shell.

The sequence of pattern - action statements can be specified in the command line as program or in one, or more, file(s) specified by the -f progfile option.

When input is read that matches a pattern, the action associated with the pattern is performed.

125 questions
1
vote
1 answer

How can I do a SQL like group by in AWK? Can I calculate aggregates for different columns?

I would like to run splits on csv files in unix and run aggregates on some columns. I want to group by on several columns if possible on each of the split up files using awk. Does anyone know some unix magic that can do this? here is a sample…
Horse Voice
  • 8,138
  • 15
  • 69
  • 120
1
vote
2 answers

Function call in Nawk command

I am not sure how to achieve the function call in the nawk command. I have given the scope what i want want from the input and output. The function should validate the column 3 and return true or false. If the column satisfies the condition then it…
Senthil
  • 83
  • 2
  • 11
1
vote
1 answer

length function in nawk command

I have the nawk command to validate if the length is greater than 12 then mark number has $ I need to use the same below command by adding one more condition i.e length should be greater than 12 and less than 17 nawk ' length($7) > 12…
user3326101
  • 51
  • 1
  • 1
  • 5
1
vote
3 answers

how do i replace the first 100 characters of all lines in a file using awk

How do I replace the first 100 characters of all lines in a file using awk? There is no field delimiter in this file. All fields are fixed width. And given the variation in the data, I cannot use a search and replace.
1
vote
1 answer

How does this NAWK script work to show the ports being used by a process on Solaris?

I am trying to understand how the following command works (from here): pfiles /proc/* 2>&- | nawk 'END { if (f) print p } /^[0-9]/ { if (f) print p, RS p = $0 f = 0 } /INET / { …
user3104542
1
vote
1 answer

using variable external like searching pattern in awk

I have next example of script: The proposal is to find ID = 67109AB inside "file.txt", using an external variable, in this case, it's called: var. But, when I run script, it doesn't take value of variable like search pattern. So, someone can help me…
1
vote
1 answer

Nawk - nawk out of space in tostring on (compare two files

i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts - compare: nawk 'NR==FNR{a[$0]++;next;} !a[$0] {print"line":" FNR $0}' file1 file2 duplicate: nawk…
1
vote
3 answers

awk use comma(optional) followed by multiple blanks as FS

What I need to do is parse a string of the following form -option optionArgument, --alternativeNotation Some text, nothing of interest... I set the FS to BEGIN { FS = ",?\ +" } but it didn't work... it should break on every random number of…
Trollhorn
  • 11
  • 3
1
vote
4 answers

How do I check for a NAWK substring being several possible values?

I am very, very much a beginner with NAWK (or AWK) but I know that you can check for a substring value using: nawk '{if (substr($0,42,4)=="ABCD") {print {$0}}}' ${file} (This is being run through UNIX, hence the '$0'.) What if the string could be…
HugMyster
  • 329
  • 1
  • 4
  • 14
1
vote
1 answer

How do I install NAWK on Windows?

I want to work with OpenCVForAndroid and a prerequisite for it is that I have Cygwin, Make and Nawk or Awk installed on my machine. I was told, and was able to, install make on my machine using CygWin. However, I do not know how to install Nawk on…
An SO User
  • 24,612
  • 35
  • 133
  • 221
1
vote
1 answer

awk failing to read contents of a large file

I'm fairly new to awk and I'm writing a script to read contents of a file process it and then append the result to few files based on the result. The script works on file containing about 100 lines but fails for a file containing 125k lines. I'm…
Aryan
  • 61
  • 2
  • 7
1
vote
2 answers

Calculate date difference between $2,$3 from file in awk

I would need your help. File with only date, file.txt P1,2013/jul/9,2013/jul/14 P2,2013/jul/14,2013/jul/6 P3,2013/jul/7,2013/jul/5 display output like this P1,2013/jul/9,2013/jul/14,5days P2,2013/jul/14,2013/jul/6,8days…
k3090
  • 25
  • 1
  • 5
1
vote
6 answers

search (e.g. awk, grep, sed) for string, then look for X lines above and another string below

I need to be able to search for a string (lets use 4320101), print 20 lines above the string and print after this until it finds the string For example: Random text I do not want or blank line 16 Apr 2013 00:14:15 id="4320101" Random…
Zippyduda
  • 107
  • 2
  • 7
  • 19
1
vote
4 answers

Separating Awk input in Unix

I am trying to write an Awk program that takes two dates separated by / so 3/22/2013 for example and breaks them into the three separate numbers so that I could work with the 3 the 22 and the 2013 separately. I would like the program to be called…
user2177896
  • 107
  • 1
  • 2
  • 7
1
vote
1 answer

awk set elements in array

I have a large .csv file to to process and my elements are arranged randomly like…
Asgard
  • 602
  • 1
  • 7
  • 18
1 2 3
8 9