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
2
votes
2 answers

alternative to tail -F

I am monitoring a log file by doing "TAIL -n -0 -F filename". But this is taking up a lof of CPU as there are many messages being written to the logfile. Is there a way, I can open a file and read new/few entries and close it and repeat it every 5…
hari
  • 9,439
  • 27
  • 76
  • 110
2
votes
4 answers

awk match search patterns and print immediate next line's 4th & 5th values

I want to match the pattern of 4th and 5th value if they matches print Nextline's 4th and 5th value. Below is the input file cat CL3-A3-2 0 0 17496 2851 P-VOL PAIR ASYNC 0 2850 - CL3-C2-5 0 0 66319 2850 S-VOL PAIR ASYNC 0 …
skmohan
  • 21
  • 3
2
votes
2 answers

Solaris awk Troubles

I'm writing a shell script and I need to strip FIND ME out of something like this: * *[**FIND ME**](find me)* and assign it to an array. I had the code working flawlessly .. until I moved the script in Solaris to a non-global zone. Here is…
pws5068
  • 2,224
  • 4
  • 35
  • 49
2
votes
1 answer

Multiple condition in nawk command

I have the nawk command where I need to format the data based on the length .All the time I need to keep first 6 digit and last 4 digit and make xxxx in the middle. Can you help in fine tuning the below script #!/bin/bash…
Senthil
  • 83
  • 2
  • 11
2
votes
4 answers

AWK: Is there a way to limit the width of an output field?

I need to limit the final size of a field to 2048. I could probably use: ACTION_PARAMETER=substr($2,1,2048); But is there a better way?
D-Klotz
  • 1,973
  • 1
  • 15
  • 37
2
votes
2 answers

AWK is it possible to read a time field and use it for sorting?

I have two files and I need to sort and merge the rows based on the time column: File A: "2014-02-26 16:03:04" "Login Success|isNoSession=false" id=csr,ou=user,dc=openam,dc=forgerock,dc=org 7efb2f0e035a0e3d01 10.17.174.30 INFO …
D-Klotz
  • 1,973
  • 1
  • 15
  • 37
2
votes
6 answers

Need to replace a specific column value of a file based on values in other columns of the file

Below is my content of file and below is my requirement Based value in column no 1 and column no 5, I would want to replace value in column 7 with "1". For example: If column 1="change" and column 5="defer", then replace value in column 7 with…
Chkusi
  • 139
  • 1
  • 5
  • 15
2
votes
2 answers

Awk syntax for enclosing {}

It is my understanding that in awk a conditional evaluation could be started using either of the following: if ($0 ~ /no/) {cmd} ($0 ~ /no/) {cmd} $0 ~ /no/ {cmd} /no/ {cmd} In the generic command line BEGIN { } (body) END { } I find it most…
gnometorule
  • 2,151
  • 2
  • 20
  • 29
2
votes
2 answers

Prevent email from being sent if nawk returns null

I was able to get my script to successfully email me at regular intervals with the help of another user here. My next question, is that I'd like for it to ONLY email me if the output is not null. I have a nawk set up to email me the output, and the…
demonic240
  • 55
  • 1
  • 5
2
votes
2 answers

nawk add column to each line

I am trying to add column with the name of the file into the end of each line. Every line has a Name Surname some_number Name and surname are separated with space and number is separated from Surname by tab. I am doing it with this script but it…
erizo
  • 347
  • 1
  • 3
  • 8
2
votes
2 answers

Extract the part enclosed by a predefined multiline character sequence

Hope the AWK gurus can provide a solution to my problem . I have a file that goes like this : cat cat cat cat cat cat dog rat ate dog tit dog cat dog dog dog rat dog pat ate cat dog I have to use AWK to extract the pattern between the first…
Gil
  • 1,518
  • 4
  • 16
  • 32
1
vote
1 answer

Shell scripting - how to get all files with a common name, and order those files

So I'm learning how powerful shell scripting is and love it, but am having a really hard time with this... I have a bunch of files named as: checkin.10 checkin.11 checkin.12 The number after the . will always be a # and goes up sequentially. I need…
user797963
  • 2,907
  • 9
  • 47
  • 88
1
vote
2 answers

How to redirect records to different output files based on a value in one of the columns in a file using nawk/awk?

How to redirect records to different output files based on a value in one of the columns in a file using nawk/awk?.. chethan RA Ramesh RA Sachin RA Gundaa DI dravid DI Suresh SE So I want to redirect RA records to one file, DI records to…
Chkusi
  • 139
  • 1
  • 5
  • 15
1
vote
1 answer

Pass variable to nawk in bash?

I'm trying to pass a variable to nawk in a bash script, but it's not actually printing the $commentValue variable's contents. Everything works great, except the last part of the printf statement. Thanks! echo -n "Service Name: " read…
user63019
  • 33
  • 3
1
vote
3 answers

accessing outer shell variables inside nawk in ksh

I am trying to access a shell variable inside a piped nawk. I have never done this before and was wondering if its possible. Here is the command sbdadm list-lu contents: Found 2 LU(s) GUID DATA SIZE …
tomkaith13
  • 1,717
  • 4
  • 27
  • 39
1
2
3
8 9