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

learn more… | top users | synonyms

3
votes
4answers
3k views

Print back-reference in regular expression

I was hoping for a way to make sed replace the entire line with the replacement (rather than just the match) so I could do something like this: sed -e "/$some_complex_regex_with_a_backref/\1/" and ...
0
votes
3answers
435 views

Inserting string from xargs into another string

Say I have some command that outputs a bunch of strings. The output from this command could look something like: ... foo bar blargh ... Say I have some set string myString$Blah I want to insert ...
1
vote
1answer
3k views

Extract substring before = sign using awk

Say I have some file with a bunch of lines in the form someString=someMoreCharacters anotherString.blah=foo=bar blah.blah.blah=foo.bar.=foobar Desired output someString anotherString.blah ...
1
vote
6answers
3k views

Pipe output of awk to kill -9

I'm trying to kill any process that has to do with mysql. I'm piecing together a command, and so far, haven't come up with the right solution. One other consideration, is that the last process will ...
2
votes
3answers
900 views

Get LVM size using AWK?

I'm in need to find out the LVM size of image vm001. Let's say I have a LVM volume called /dev/VGgroup/vm001. Now using lvdisplay I can find out the size: --- Logical volume --- LV Name ...
3
votes
4answers
2k views

How to remove lines from large text file using bash

I got a huge text file (log file) in my CentOS which I would like to remove top part of, probably couple of thousand lines each day. (Or probably just split into two) I have search this site and ...
4
votes
3answers
912 views

how to limit find command's output used with option -print0

I'd like to limit output of find command. In the past I used to use for this ls command, e.g: ls *tgz|head -100|xargs -i mv "{}" ../ but I got to know that the result may be unpredictable if name ...
2
votes
2answers
2k views

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 ...
2
votes
1answer
223 views

awk: equivalent of mysql's “\G” to print tabulated data in multiple lines

Is there an equivalent to mysql's "\G" at the end of the query but awk (or similar) that will to print tabulated data from a text file in multiple lines with the header next to it? Something that will ...
0
votes
3answers
427 views

Oneliner for multiline regex s/,\n]/]/g?

Can someone provide a simple one-liner to remove certain line breaks? In vim I use %s/,\n]/]/g This should be possible with a very simple one-liner IMHO, but how?
0
votes
0answers
178 views

How can I improve or wrap my sed-script?

I instrumented a mvn build to emit profiling data, which I want to analyse later on. Therefore, I made the sed script below, to generate json-data from the profilers output. I call the script with ...
0
votes
1answer
213 views

how to redirect output of command line execution to more than one file according to weight of output

Currently I'm using an awk line to filter a set of files according to certain criteria. How can I redirect the result output to more than one file if the result, for example if the file that would ...
2
votes
2answers
325 views

Awk responds differently based on how an empty argument is specified

I seem to have stumbled on something which is probably a bug in awk, but it could also be a bug in my understanding of bash/awk. I was trying to debug issues where the output of a python program was ...
0
votes
1answer
282 views

usermod + awk invalid syntax

I have been trying to write a command (Solaris server) that adds a user to a specific group. It's a pretty long command so I'll post the whole command here and then break it down. USER=myUser ...
9
votes
5answers
2k views

Removing ANSI color codes from text stream

Examining the output from perl -e 'use Term::ANSIColor; print color "white"; print "ABC\n"; print color "reset";' in a text editor (e.g., vi) shows the following: ^[[37mABC ^[[0m How would one ...
0
votes
1answer
264 views

awk + sed + match complex string

I need useful command to match the string "/pci.../pci.../pci..../scsi..../disk..." with awk or sed? ( I need to put this command in my ksh script ) remark 1 [...] can be any string , and “pci pci ...
1
vote
3answers
2k views

How to pipe awk output (with periodic, continuous input) to output file?

I am trying to write a command that pipes the continuous output of a free command (run every second) to an awk command that parses a specific value (available free memory) and outputs this to a file ...
3
votes
1answer
3k views

“No such file or directory” for /bin/awk on Ubuntu

How can I install awk in this version of Ubuntu 11? I installed it from Ubuntu Software Center and I cannot use it. I'm trying to run an awk script: #!/bin/awk Begin { print strftime("ora ...
0
votes
1answer
138 views

How to reconnect a screen session every time terminal is fired?

I wrote this command to reconnect an active screen session when Terminator is opened. It works find but there has got to be a better way to to it This is goes in the Terminator config file (note ...
1
vote
2answers
371 views

How to pass bash variables (passwords) to IRSSI config file?

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

What's the best command to use to change a timestamp to readable date when 'tail -f'-ing a log file?

I have a program which logs like this: 1324218770.7644 INFO etc What's the best Linux shell program to pipe that through to change the timestamps to a human readable format like Sun 18 Dec 2011 ...
0
votes
2answers
1k views

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 ...
1
vote
1answer
474 views

How to solve “Broken Pipe” error when using awk with head

I'm getting broken pipe errors from a command that does something like: ls -tr1 /a/path | awk -F '\n' -vpath=/prepend/path/ '{print path$1}' | head -n 50 Essentially I want to list (with absolute ...
2
votes
2answers
2k views

awk match whole word

I want to use awk to match whole words from text file. Including words bounded by non alphanumeric characters. For example - string to search for - ABC Source file - HHHABCCCCH HHH ABC ...
1
vote
2answers
598 views

File name with spaces piped to two xargs commands

I have a directory and many more subdirectories like the following - file with spaces.txt filewithsuperlonglines.txt ordinaryfile.txt binaryfile.bin The command - find . -type f -print0 | ...
0
votes
1answer
634 views

“find | grep | awk” fails miserabily

I'm scanning for all shell scripts on my server, and are doing this by the following command: find / -type f -exec file --mime-type {} \; | grep "text/x-shellscript" This is working fine, and here ...
0
votes
4answers
2k views

Use variables in awk substr function

All, I have a string from which I want to extract a substring. The thing is that the starting position is stored in variable. AWK Doesn't seem to recognize the variable. Here is the code str="This ...
2
votes
2answers
145 views

determine start of file when passing multipe files to awk

I have a shell script like the following - find "." "Account" -maxdepth 1 -name "*.aspx" | xargs awk -f get_controls.awk It passes multiple files to an awk script BEGIN{ FS="\"" } ... ...
1
vote
1answer
751 views

How do I sort the “/etc/passwd” UIDs?

I have been banging my head on this little project the past few days and here is how it goes... I need to organize all the UIDs for multiple servers so all users have the same UID in their ...
2
votes
2answers
863 views

Unix one-liner to quote all words on a line

I have a text file which has lines consisting of words (separated by spaces) and I want to put quotes around all of the words. For example: Lorem ipsum dolor sit amet consectetur adipisicing ...
2
votes
2answers
583 views

Join two lines with awk or sed

If I have: foo bar ..and I'd like to awk/sed this to: foo-bar ..what's the syntax? I'm trying to use System Profiler on OS X 10.6.x: system_profiler SPMemoryDataType | awk '/Type/ {print $2} ...
0
votes
1answer
222 views

AWK CSV stream editing, merge third columns for identical first columns when second column >= 0

I'm on Windows and have only heard of linuxes awk etc so I can only imagine that this is possible without actual scripting: I have data like .. 162 42 A single serving 162 62 of ...
1
vote
3answers
356 views

SW to replace a string in Windows

I have a text file (actually XML) that I want to be able to change using a command line. In other words, as part of a Windows batch, I want to locate a string (in this case @@@@, which uses a ...
0
votes
2answers
627 views

Truncate all files in a directory after underscore?

I have a directory with a couple thousand images in it. Most of them have sensible filenames like SD-000.tif SD-001.tif BX-000.tif etc... However probably ~25% of them have names like BX-003_old.tif ...
1
vote
2answers
853 views

Shell: Find and replace word

I have a string in my shell script which is in a fixed format : '[STATUS REPORT] PROJECT'. When user executes my shell script he will be asked to provide a value for 'PROJECT'. I would like to ...
0
votes
2answers
120 views

lines identical except for their first word, put the first word in a variable

I have file(sudoers) in which lines can be identical except for the first word in them (different users can execute the same set of commands). I am able to extract such a line using the command: # ...
0
votes
1answer
725 views

Getting the week number based on date with different first day of the week in gawk

How to get the week number in linux using gawk with different first day of the week? the date command can give me the week number with +%V but it is based on Monday (1-53) or +%U (based on Sunday, ...
1
vote
1answer
316 views

awk + find hostname after strings

please advice how to print the hostname ( NODE100 ) from the tnsnames.ora file by awk or sed I mean I want to get each hostname after "HOST =" or "HOST=" or "HOST =" etc thx ...
1
vote
2answers
413 views

Sort multiple files with bash

I have a question that involves the bash scripting language. I have multiple directories /studentName /studentMail /studentNumber In each of these directories is a file name.txt, mail.txt, ...
2
votes
1answer
109 views

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.
4
votes
1answer
535 views

how to move around files using “ls -al” result in Linux?

How can I write a script to copy files from one directory to another directory according to last modified date? ls -al -rw-r--r-- 1 user user 100 2011-05-26 12:33 ...
0
votes
0answers
230 views

Reset awk field separator

On my local system, it appears that the configuration for awk has somehow been changed. Running the following command: echo "Hi there" | awk '{print $2}' On my machine this prints: Hi there And ...
8
votes
3answers
7k views

Filtering top command output

I'm running a Mac and want to filter the output of the top command for a particular process such that only the PID, COMMAND and %CPU columns are displayed. After getting the PID of the process, I ...
0
votes
1answer
3k views

How to construct a grep command with a variable argument in bash?

I'm trying to do something like this in bash: grep ( date | awk '{print "2006-" $6}' ) /some/file/here But that syntax is incorrect. The goal is to grep /some/file/here for the pattern 2006-2011 ...
0
votes
1answer
3k views

grep the specific date patterns

I have a requirement, where i need to grep from the logs which covers from date range 2011/03/25 to 2011/04/04 (YYMMDD). I have done this with egrep command, seems to be working fine for me. cat ...
2
votes
2answers
319 views

Rename sets of files based on size

Background Rename one set of files based on a name that corresponds to another set, using a sort order based on file size to match the file names. The files from both sets have approximately the same ...
0
votes
4answers
772 views

using awk to make exact matches

i'm just wondering how can we use awk to do exact matches. for eg $ cal 09 09 2009 September 2009 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...
0
votes
2answers
204 views

how to change the existing printed line in AWK

when i execute the following line, its prints the words in newline. awk 'BEGIN { print "line one\nline two\nline three" }' like line one line two line three How can i print the info in the same ...
0
votes
3answers
668 views

Optimize shell and awk script

I am using a combination of a shell script, awk script and a find command to perform multiple text replacements in hundreds of files. The files sizes vary between a few hundred bytes and 20 kbytes. ...
2
votes
3answers
292 views

Copied directory appears to become larger at destination

I have the following code as part of a shell script: while [ $(ps -ef | awk '{print $2}' | grep -F "$CPPID") ]; do sleep 10 awk -v "usbsize=$(/bin/df | grep -F $DEVICEMOUNTPOINTQ | awk ...