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.

learn more… | top users | synonyms

1
vote
2answers
316 views

Using wget and Awk to count similar expressions

I am trying to create a script that uses wget to download a data set and then awk to sort though the file and tell you the most common filter used which is $14 column. So far I have the wget function ...
-3
votes
3answers
696 views

How to pass the output of a command as a variable in a bash script?

I'm trying to pass the output of an awk command as a variable in a bash script, but not having much success so any help is appreciated. homedirectory=$(awk /stephen/ /etc/passwd | awk -F/home/ ...
2
votes
2answers
163 views

awk + perl + get two arguments in to awk syntax

please advice what wrong with my awk syntax and how to fix it ( this syntax is in my ksh script ) and I run my script on linux machine my target is to get from the file.txt only the lines that ...
0
votes
1answer
151 views

cutting relevant portions of a file [closed]

I want to cut some portions of binary file starting from a particular pattern and ending at a particular pattern.How do I do that in linux using bash.Can this be done using sed or awk? I have a file ...
1
vote
2answers
668 views

Grep to find lines starting at pattern A until pattern B is matched

I have a log that contains bits like this: [2012-04-16 15:16:43,827: DEBUG/PoolWorker-2] {'feed': {}, 'bozo': 1, 'bozo_exception': URLError(error(110, 'Connection timed out'),), 'entries': []} ...
-1
votes
3answers
179 views

linux + generate new file with specific structure from text file what the best option

in my Linux machine I have the file orig-file.txt this file include now 4 fields but they could be less or more ( this file generate by other application ) I need advice - what the best option to ...
4
votes
2answers
927 views

AWK and file names with space in it.

I'm trying to parse files with awk to change their names. Everything went well until im started to do this with files with space in file name. File names are something like 11237_712312955_2012-01-04 ...
18
votes
6answers
5k views

bash/sed/awk/etc remove every other newline

a bash commands outputs this: Runtime Name: vmhba2:C0:T3:L14 Group State: active Runtime Name: vmhba3:C0:T0:L14 Group State: active unoptimized Runtime Name: vmhba2:C0:T1:L14 Group State: active ...
1
vote
3answers
416 views

append to end of line sed / awk

This is probably easy and something is not clicking for me and my lack of coffee right now. I have a file with multiple lines that begin with a tab then the word GROUP something { Some of these lines ...
2
votes
4answers
2k views

What command can I use to search sendmail logs for ALL message details involving a specific recipient.

CENTOS 5.x | Sendmail Occasionally I need to search through sendmail delivery logs to find out what happened to a missing message. This usually involves two (or more) steps: STEP 1: Search ...
0
votes
3answers
79 views

shell script + match MAJOR and CRITICAL strings from log file

I need to match lines that have MAJOR and CRITICAL strings that comes after the word ERROR:< any integer number > please advice how to do that with one awk or sed command? more HW_Log.txt ...
6
votes
4answers
3k views

Linux shell command to filter a text file by line length

I have a 30gb disk image of a borked partition (think dd if=/dev/sda1 of=diskimage) that I need to recover some text files from. Data carving tools like foremost only work on files with well defined ...
3
votes
2answers
850 views

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 ...
3
votes
2answers
644 views

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 ...
4
votes
4answers
5k views

Parse and convert ini into bash array variables

I'm trying to convert an ini file into bash array variables. The sample ini is as below [foobar] session=foo path=/some/path [barfoo] session=bar path=/some/path so these become ...
0
votes
1answer
257 views

Sanitizing dates using sed or awk on an ldapsearch query

I'd like to pipe the output of an ldapsearch to sanitize the dates returned - I presume sed and/or awk can help with this but would appreciate a bit of help. The fixed length date format in the LDIF ...
2
votes
3answers
935 views

awk on vmstat to get si,so

I am writing a shell script to check the vmstat si and so data at various time intervals vmstat 1 sample output: procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b ...
1
vote
5answers
245 views

Extracting lines from a file based on prefix

I need to extract all lines from file2 that begin with an id # prefix contained in file1. File 1 is single column like: 324 399 408 135236 321590 File 2 is multi-column like: 1 [tab] 108 [tab] ...
0
votes
1answer
80 views

Parse value of $DatabasePassword from RT_SiteConfig.pm

I'm writing a Bash shell script to backup our Request Tracker (RT) MySQL database on a daily basis. Instead of hard-coding the MySQL database user's password in the shell script I'd like to parse it ...
1
vote
4answers
321 views

double awk commands in same pipe?

Hello I'm trying to do something like this but it wont work, can you guys tell me help me out? /usr/bin/mysql -B -r -h ******** -u******* -p****** -D***** \ -e'SELECT `username`, `uid`, `gid`, ...
16
votes
7answers
1k views

Can awk be used instead?

I would like to get the number from rating as output from this # nc localhost 9571 language: language:en_ZA.UTF-8 language:en_ZW.UTF-8 session-with-name:Ubuntu Classic (No effects):gnome-session ...
19
votes
3answers
737 views

Best way to get the MAC of eth0?

Is there a more efficient way to retrieve the MAC address of a NIC in Linux? This works: ip link show dev eth0 | awk ' /link\/ether/ { print $2 }' but can it be found via something like: cat ...
2
votes
5answers
473 views

How to remove a certain symbol for a bash script

I have a bash script where I get the disk usage, for example 60%. How can I remove the % symbol? Using grep or awk?
3
votes
2answers
1k views

Multiline data list (ldif file) manipulation with awk or other tool

I'm trying to manipulate an ldif file with multiple entries. My purpose is to parse this existing ldif file, extracting the "givenName" and "sn" attributes, so to generate a "mail" attribute. I was ...
0
votes
3answers
564 views

Parsing a diff file using grep/awk

I'm trying to parse a standard diff of some sql files to return only the delete sections. I have been using grep with the after context (-A) which almost works (only because I know that delete ...
0
votes
3answers
829 views

AWK - Is it possible to search for pattern, then sort results based on a wildcard?

I am storing a number of individually serialized PHP arrays to a file. Each line of the file contains one serialized array. For example: a:2:{s:4:"name";s:8:"John Doe";s:3:"age";s:2:"20";} ...
1
vote
1answer
243 views

Using Find, Grep, Awk, or Sed To Rename Server After Cloning

My client tells me they have cloned a VM in VMWare of an Ubuntu Linux server. Now it's my job to get into all the files and find out what still has the old server name of "bishop" and change it to ...
1
vote
4answers
733 views

Bash: delete all but most recent n files with prefix x

I have a directory of backups that looks like this: -rw-r--r-- 1 ftpuser ftponly 5610595 May 27 00:01 alpha-114.tar.asc -rw-r--r-- 1 ftpuser ftponly 50559368 May 27 00:04 beta-211.tar.asc ...
1
vote
3answers
155 views

alias to replace a text in file

here is a practical situation.I facing some of my files where there is a common string in these files.I usually will open vi and do some thing like :%s/text/replacement/g and I have to do it in ...
21
votes
8answers
39k views

how to find out mac addresses of all machines on network

Is there some easy way to find out mac address of all machines on my network rather than doing an SSH into each and ifconfig | grep HWaddr if there are 300 machines on network I really need some easy ...
1
vote
3answers
443 views

Passing variables problem - Bash

I have a following problem: #!/bin/bash NUM=`cat accounts | wc -l`; for i in {1..$NUM} do account=`awk "NR==$i" accounts`; echo -e "\nAccount: $account\n"; sudo ./backup_maildir $account; ...
1
vote
1answer
382 views

Need help on awk/sed/ perl pattern with regex / grep

Sample file output from grep file1:my $dbh = DBI->connect("dbi:mysql:$database_name", $DB_USER, $DB_PASSWD) file2:($dbc,$rc) = mysql_connect($mysql_host,$mysql_user,$mysql_password); The awk ...
2
votes
3answers
370 views

Shell script to block proftp failled attempt

I want to filter and block failed attempt to access my proftp server. Here is an example line from the /var/log/secure file: Jan 2 18:38:25 server1 proftpd[17847]: spy1.XYZ.com ...
3
votes
2answers
1k views

Color awk output on commandline?

When i process a logfile in awk, is there a possibility to colorize the output on commandline?
0
votes
2answers
2k views

sed/awk: extract one number from string

I have many lines like the following being returned from a bash command, with different sourceNodeIds of varying digit lengths: <NodeAssociation sourceNodeId="33654" [...] sourceNodeEntity="Issue" ...
0
votes
1answer
339 views

How can i Move or copy files (or folder) from solaris server to removable disk.(Backup Tape drive)

i need to move or copy some zip(.tar,.gz,.Z) files from solaris server to Backup tape drive and also i want to retrive from tapedrive when ever i want without any loss. kindly expain the procedure. i ...
3
votes
1answer
125 views

Unexpected Awk results with sh -c

I am trying to sudo a command that uses Awk, and it looks like awk works differently inside sh -c. echo '1 2' | awk '{print $2}' 2 sh -c "echo '1 2' | awk '{print $2}'" 1 2 Why is this ...
0
votes
2answers
600 views

Parse java console output with awk

I'm trying to use awk to parse an output generated by a java application, but it isn't working. It seems that the command after the pipe isn't able to get/see the data throwed by the java app. I'm ...
0
votes
2answers
1k views

Is it possible to insert data from AWK into MySQL

Can i use mySQL from inside awk code Basically i want the data AWKED in this post into Mysql database
4
votes
5answers
1k views

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?
4
votes
2answers
232 views

Perl search & replace

How can I use search and replace to change the contents of a file. I need to be able to change the 'all to none' and/or 'none to all' without having to manually do it every time for hundreds of ...
2
votes
7answers
7k views

How to show available disks on a Linux system?

If i run fdisk -l I get an output as: Disk /dev/sda: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: ...
0
votes
2answers
439 views

Running (vertical?) diff on columns in a file

in our company we pull in inventory files from third parties. These files are in a fixed format, containing the 13-digit EAN (think UPC code) as well as other data. I also have a master list of EANs ...
0
votes
4answers
167 views

do… while loop in original 1978 awk?

Does the do... while loop work in the original awk? Or has it been introduced in later implementations (nawk, gawk, ...)? Can nawk be considered present on all Unix platforms today? Greets, Oliver
1
vote
5answers
1k views

bash script - print from line N to EOF

I want to be able to print the number of lines from bash as such: Line number (as counted from the top) -> end of the file It seems tail will only count lines from the bottom. Does anyone know how ...
1
vote
3answers
2k views

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, ...
38
votes
12answers
41k views

Do you have any useful awk and grep scripts for parsing apache logs?

I can use log analyzers, but often I need to parse recent web logs to see what's happening at the moment. I sometimes do things like to figure out top 10 ips that request a certain file cat foo.log ...