Questions tagged [awk]

AWK is a text-processing language. It is mainly used to manipulate and process structured data, and to generate reports.

AWK is a programming language created by Alfred V. Aho, Peter J. Weinberger and Brian W. Kernighan for processing text-based data, whether from files or data streams.

AWK is an example of a programming language that extensively uses the string datatype, associative arrays (that is, arrays indexed by key words) and regular expressions. The power, terseness, and limitations of programs made ​​in AWK and sed scripts inspired Larry Wall to create the Perl language.

629 questions
18
votes
2 answers

How can I find my awk version?

If I want to know the version of awk I get the following: $ awk --version awk: not an option: --version Checking in man awk I see that my awk is mawk - pattern scanning and text processing language
fedorqui
  • 1,967
  • 1
  • 18
  • 37
9
votes
3 answers

Round off the decimal value in awk

i want to round off the value 262.5 to 263 using awk i have tried the below echo "262.5" | awk '{printf "%.f\n", $1}' My expected answer is 263
Bharath
  • 109
7
votes
5 answers

Using awk to split text file every 10,000 lines

I have a large gzip'd text file. I'd like to something like: zcat BIGFILE.GZ | \ awk (snag 10,000 lines and redirect to...) | \ gzip -9 smallerPartFile.gz the awk part up there, I basically want it to take 10,000 lines and send it to gzip…
6
votes
8 answers

awk + print all line content except $1

I write the follwoing awk script: % echo /var/sysconfig/network/my_functions alpha beta gama | \ awk -v word=alpha '$2 == word { print $0 }' how to tell awk that I want to print all line except $1 (/var/sysconfig/network/my_functions PATH…
jennifer
  • 1,117
5
votes
2 answers

Is it possible to change the default field separator in awk?

I'm always using awk to manipulate comma separated files, so the first line in my code is always changing the field separator to "," like so: awk 'BEGIN {FS=","} $2 < 20 {print $1}' myfile.csv Is it possible to change awk's defaults so that comma…
evsmith
  • 183
4
votes
1 answer

writing an AWK command

My input file has three columns like the one below Input file: water 123 wa water 123 at water 123 te water 123 er rater 347 ra rater 347 at rater 347 te rater 347 er Now I want my output file to be like the one…
Mani
  • 41
4
votes
3 answers

How can I insert a line in the middle of a file, with awk, given a search pattern to insert AFTER or BEFORE

I want to insert some text in the middle of a file. The text to insert would be after a specific line, say, "". I don't know the line number, nor do I know the number of lines in the text to insert. I only know that after the line that reads…
jfmessier
  • 2,780
3
votes
1 answer

why can awk function called without parentheses

Is print a function or statement. Why parentheses are not required? I couldn't find any information about this topic.
kev
  • 12,730
3
votes
3 answers

awk + print from the third field until end of line each word with one space

How do I print all $Organs words (from the third field) with one space between each Organ to another? My problem is that each $Organ param have different Organs number so I cant to guess the last field number. I need awk syntax that print the…
jennifer
  • 1,117
3
votes
1 answer

Strange awk syntax: Number with two dots?

By accident I did gawk 'BEGIN { print 1.2.3+4; }' and received 1.24.3 I expected a syntax error because of the two dots in the number. What happened here ? Is that a bug in GNU awk or is it a feature ? Same result with these versions:GNU Awk…
Juergen
  • 578
  • 6
  • 24
2
votes
1 answer

Weird behavior of awk

Why do I get only "cat" when I run awk 'BEGIN { animal[three] = "hen" animal[two] = "dog" animal[one] = "cat" for (var in animal) { print animal[var] } } ?? Shouldn't it print "hen", "dog" and "cat"?
anilomjf
  • 121
2
votes
2 answers

awk search in specific columns

We have a file like this (with many more lines): BeginJobID=S0065546 JESMSGLG(1/281) jname=CICWCMWD queue=EXECUTION JESMSGLG(2/281) BeginJobID=S0065568 jname=CICWWUWD queue=EXECUTION JESMSGLG(3/281) jname=CICWMCWD BeginJobID=S0065569…
2
votes
3 answers

how to write `awk here document`

I have a bash script: #!/bin/bash gawk -f realmap.awk realmap.log | column -ts: > realmap.csv gnuplot <<-_EOF_ set term png set out 'realmap.png' set xlabel 'index' set ylabel 'bytes' set style data lp plot 'realmap.csv' u…
kev
  • 12,730
2
votes
1 answer

awk + cut file between lines from ext ARG

I have the following awk commnad I want to cut the file from start to end please advice why awk not work awk -v PARAM=start -v PARAM1=end '/PARAM/,/PARAM1/' file file: 2324 443 start 43 end 545 required file start 43 end
jennifer
  • 1,117
2
votes
3 answers

AWK is printing all columns

I want to isolate the second column. If I do: echo "1 2 3" | awk "{ print $2 }" the result is: 1 2 3 The expected result is: 2 I've tried with -F' ' option, but the result is the same. What am I doing wrong?
1
2 3 4