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

grep regex to perl or awk

I have been using Linux env and recently migrated to solaris. Unfortunately one of my bash scripts requires the use of grep with the P switch [ pcre support ] .As Solaris doesnt support the pcre option for grep , I am obliged to find another…
Gil
  • 1,518
  • 4
  • 16
  • 32
7
votes
3 answers

Extract a specific pattern from lines with sed, awk or perl

Can I use sed if I need to extract a pattern enclosed by a specific pattern, if it exists in a line? Suppose I have a file with the following lines : There are many who dare not kill themselves for [/fear/] of what the neighbors will say. Advice is…
Gil
  • 1,518
  • 4
  • 16
  • 32
6
votes
4 answers

Separating output records in AWK without a trailing separator

I have the following records: 31 Stockholm 42 Talin 34 Helsinki 24 Moscow 15 Tokyo And I want to convert it to JSON with AWK. Using this code: #!/usr/bin/awk BEGIN { print "{"; FS=" "; ORS=",\n"; OFS=":"; }; { if (…
AlexStack
  • 16,766
  • 21
  • 72
  • 104
6
votes
1 answer

Change regex delimiter in awk patterns

Is is possible to change the default regex delimiter (slash) to other characters? I tried to do it using with sed syntax but it didn't work. $ gawk '\|bash| { print } ' backup.sh gawk: |bash| { print } gawk: ^ syntax error The regex I am trying has…
Anvesh
  • 395
  • 1
  • 2
  • 10
5
votes
3 answers

Is Awk and multiple file processing possible?

I need to process two file contents. I was wondering if we can pull it off using a single nawk statement. File A contents: AAAAAAAAAAAA 1 BBBBBBBBBBBB 2 CCCCCCCCCCCC 3 File B contents: XXXXXXXXXXX 3 YYYYYYYYYYY 2 ZZZZZZZZZZZ 1 I would like…
tomkaith13
  • 1,717
  • 4
  • 27
  • 39
4
votes
3 answers

How to handle 3 files with awk?

Ok, so after spending 2 days, I am not able solve it and I am almost out of time now. It might be a very silly question, so please bear with me. My awk script does something like this: BEGIN{ n=50; i=n; } FNR==NR { # Read file-1, which…
Bhushan
  • 18,329
  • 31
  • 104
  • 137
4
votes
4 answers

Remove what follows Nth occurrence Using one-liners

I would like to remove what follows the forth occurrence of the character ":" in any field contains it. See the example: Input: 1 10975 A C 1/1:137,105:245:99:1007,102,0 0/1:219,27:248:20:222,0,20 1 19938 T TA ./. …
user1421408
  • 207
  • 2
  • 9
4
votes
7 answers

Transpose rows into column in unix

I have input file which is given below Input file 10,9:11/61432568509 118,1:/20130810014023 46,440:4/GTEL 10,9:11/61432568509 118,1:/20130810014023 46,440:4/GTEL Output which i am looking…
gyrous
  • 189
  • 3
  • 6
  • 19
3
votes
2 answers

Array size in nawk

I am reading Introduction to Arrays for nawk It says: Arrays in awk superficially resemble arrays in other programming languages; but there are fundamental differences. In awk, you don't need to specify the size of an array before you start to…
hari
  • 9,439
  • 27
  • 76
  • 110
3
votes
1 answer

exit out of an awk function

How do I exit out of an awk function? "exit" stops entire program?
hari
  • 9,439
  • 27
  • 76
  • 110
3
votes
1 answer

Printing lines according to their columns in shell scripting

i know it is very basic question but im total new in shell scripting i a txt file called 'berkay' and content of it is like 03:05:16 debug blablabla1 03:05:18 error blablablablabla2 05:42:14 degub blabblablablabal 06:21:24 debug balbalbal1 I want…
abidinberkay
  • 1,857
  • 4
  • 36
  • 68
3
votes
2 answers

Different results from awk and nawk

I just ran these two commands on a file having around 250 million records. awk '{if(substr($0,472,1)=="9") print $0}' < file1.txt >> file2.txt and nawk '{if(substr($0,472,1)=="9") print $0}' < file1.txt >> file2.txt The record length is 482. The…
Ankit
  • 1,250
  • 16
  • 23
3
votes
5 answers

How to print lines from a file that have repeated more than six times

I have a file containing the data shown below. The first comma-delimited field may be repeated any number of times, and I want to print only the lines after the sixth repetition of any value of this field For example, there are eight fields with…
Mike
  • 55
  • 6
2
votes
1 answer

Script with nawk doesn't print output to screen

I came across a nice one-liner to search for text and print out the results with a given number of trailing and following lines. I'm trying to create a script out of this. So far this is what I have: #…
Gayan
  • 1,697
  • 7
  • 26
  • 35
2
votes
1 answer

Regarding nawk and system command

I am working on Solaris and working on a script that turns on any disabled service . Here is the output file: disabled 7:22:05 svc:/network/bla-bla:default online Jun_14 svc:/network/blu-blu:default I would like my code to parse…
tomkaith13
  • 1,717
  • 4
  • 27
  • 39
1
2 3
8 9