Questions tagged [awk]

The AWK utility is a data extraction and reporting tool that uses a data-driven scripting language consisting of a set of actions to be taken against textual data (either in files or data streams) for the purpose of producing formatted reports.

The AWK utility is a data extraction and reporting tool that uses a data-driven scripting language consisting of a set of actions to be taken against textual data (either in files or data streams) for the purpose of producing formatted reports. The language used by awk extensively uses the string datatype, associative arrays (that is, arrays indexed by key strings), and regular expressions.

AWK was created at Bell Labs in the 1970s, and its name is derived from the family names of its authors — Alfred Aho, Peter Weinberger, and Brian Kernighan.

194 questions
3
votes
2 answers

How to add the filename as prefix to each line of the text file? (batch processing; subdirectories)

I have many .txt files with their filenames being different dates: 01.01.2010.txt 02.01.2010.txt ... Currently each file (e.g.: 01.01.2010.txt) looks like this: 0.351 XXX XXX XXX XXX 0.292 XXX XXX XXX XXX How do I add the filename…
user3200534
  • 392
  • 1
  • 3
  • 10
3
votes
2 answers

AWK + Host lookup

Currently using the following line to get top 20 ips sorted by requests: grep 'GET /' /var/log/nginx/access.log | awk '{ print $1 }' | sort -n | uniq -c | sort -rn | head -20 Output: 575 66.249.*.* 570 66.249.*.* 534 207.46.*.* 511 157.55.*.* 493…
Bastien
  • 123
  • 2
  • 12
3
votes
2 answers

how to get the desired value in bash shell from the lshw output?

I want to extract the info from lshw output where it says: -cpu product: ...... I want only the product info of this -cpu. How can I do that with awk or sed?
UnixUser
  • 43
  • 2
3
votes
3 answers

Year Month day from file name in shell script

I hava file names like below adn_DF9D_20140515_0001.log adn_DF9D_20140515_0002.log adn_DF9D_20140515_0003.log adn_DF9D_20140515_0004.log adn_DF9D_20140515_0005.log adn_DF9D_20140515_0006.log adn_DF9D_20140515_0007.log i want get the year, Month,…
user3319390
  • 31
  • 1
  • 3
3
votes
2 answers

Extracting a line section of mysql backup using sed

I occasionally need to extract a single record from a mysqlbackup To do this, I first extract the single table I want from the backup... sed -n -e '/CREATE TABLE.*usertext/,/CREATE TABLE/p' 20120930_backup.sql > table.sql In table.sql, the records…
carpii
  • 541
  • 2
  • 4
  • 12
3
votes
2 answers

How can I add a line break before a set of values going into a bash script?

I've got a set of data piping into a bash script. Here's an example of what that data looks like: "foo1": "Miscellaneous text", "foo2": "More text", "foo3": "blah blah blah", "foo4": 1635.0, "foo5": 0.0, "foo1": "Miscellaneous…
Mike B
  • 11,871
  • 42
  • 107
  • 168
3
votes
1 answer

Alternatives to gnuplot+awk?

I've needed to do some more sophisticated graphing and plotting as of late. While I know that gnuplot is up to the task, and can do it all from the command line, are there other, simpler or more powerful tools that I'm missing? I'm a bit oldschool,…
mgjk
  • 874
  • 3
  • 9
  • 20
3
votes
2 answers

Octal representation of file/folder permissions using awk?

We have various of machines here with all sorts of hardware and Operating Systems, most of them do regular tasks with bash that an agent executes. However it came to my attention that some Solaris machines we own do not have stat util, and adding it…
dotdot
  • 33
  • 4
3
votes
2 answers

How do I use sed or awk to remove text?

I have the following line in a file: Linux Release............5.4.2.0-02 12_12_2011_07:31:23 How do I remove all characters before the first number with sed or awk? I wish to get the following result: 5.4.2.0-02 12_12_2011_07:31:23
Eytan
  • 611
  • 6
  • 13
  • 27
3
votes
5 answers

Is it worth while to learn Awk?

I am decent with bash scripting and I am catching on to regex, and a little sed usage. Is learning awk still worth while with all the alternatives out there. Opinions?
Thomas Dignan
  • 211
  • 3
  • 13
3
votes
1 answer

How to correctly escape single quotes in AWK

It isn't clear exactly what more needs to be escaped in the following macro to allow it to be used with awk or sed on FreeBSD. define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl Here is an awk command that attempts to insert the above line at line 90…
Utkonos
  • 416
  • 4
  • 15
2
votes
2 answers

AWK help filter data into CSV

We are doing some security research for which I need to extract from Debian repos all available package names, versions, desc, etc. I'm trying to parse output of apt-cache dumpavail into CSV and organise data into tabular form like name, version,…
Gagan Pal
  • 33
  • 7
2
votes
3 answers

using awk in a bash script with if

I'm doing a script in which I need to test a string and based on its result I'll decide if I go further or not. The command below works fine (if the string starts with "Clean" it will print 1, otherwise 0). echo | awk ' {print index("'"${task}"'",…
Bob Rivers
  • 516
  • 5
  • 13
2
votes
2 answers

Pipe grep result to awk with ": " as field separator

I would like to filter the result of a grep command, eg : myRepo/path/to/my/file.php:123: error_log(' - myError'); If I do the following, it works. echo " myRepo/path/to/my/file.php:123: …
Bastien974
  • 1,896
  • 12
  • 44
  • 62
2
votes
3 answers

awk ignores the record separator I set for the first record

I am trying to change the record separator but awk does not use the record separator I set until the second record and beyond. I get output like this: ARRAY /dev/md4 level=raid1 num-devices=2 metadata=0.90…
menders65
  • 25
  • 6
1 2
3
12 13