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 ...
0
votes
3answers
33 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
...
0
votes
4answers
50 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
88 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
66 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 ...
0
votes
0answers
7 views
How to pass bash variables (passwords) to IRSSI config file? [migrated]
I'm using IRSSI and I wonder how can I pass my IRC channel's passwords to the IRSSI config file (~/.irssi/config) without writing them directly in the file.
In Mutt I've an awk command that queries a ...
4
votes
3answers
88 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
45 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
118 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
90 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
26 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
72 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`, ...
17
votes
6answers
752 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 ...
18
votes
3answers
443 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
84 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?
2
votes
2answers
143 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
201 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
162 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
95 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
135 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
102 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 ...
6
votes
6answers
2k 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
194 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
185 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
191 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 ...
2
votes
2answers
405 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
493 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
160 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
73 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
329 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
680 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
1
vote
5answers
556 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. I am kind of averse to using perl, I see ...
4
votes
2answers
148 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
6answers
745 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
254 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
121 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
557 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
784 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, ...
20
votes
10answers
11k 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 ...