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

2
votes
1answer
257 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
478 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
185 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
238 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
429 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
340 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 ...
12
votes
6answers
4k 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
282 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 ...
3
votes
3answers
4k 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
5k 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
160 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
420 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
365 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
653 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
3k 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
707 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
749 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
3k 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
184 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
929 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
1k 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
692 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
241 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
424 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
902 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
1k 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
133 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
908 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
412 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
513 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
110 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
641 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
1answer
447 views

Perform a math operation on all numbers in a file

I have a list of pixel values in a file, and need each to be half its current value. The pattern for the value is always 123px where 123 varies drastically. How can I half each pixel value? I'm ...
0
votes
0answers
272 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 ...
9
votes
3answers
9k 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
4k 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
4k 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
1answer
357 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
896 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
247 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
802 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
321 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 ...
-2
votes
3answers
488 views

Problem executing in linux command [closed]

I'm executing a Linux command and executing from an automated script. ps | awk '/dspload -d 1 -e/&&!/awk/{print $1}' Now when I see the logs of the script and look at the location where it ...
3
votes
1answer
2k views

Reading output of shell command in awk script

I have a text file with a list ip addresses and other information. I am using an awk script to process this list and output various computations. I want to call dig -x from inside the awk script and ...
2
votes
5answers
4k views

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 ...
3
votes
3answers
9k views

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

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, "<begin>". I don't know the line number, nor do I know the number of lines in the text ...
2
votes
1answer
269 views

awk + cut file between lines from ext ARG

hi 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 ...
1
vote
2answers
947 views

Adding and removing fields to a text file

I would like to write a script (probably AWK printf related) that will take my delimited file, remove some unwanted fields and add some additional fields througout the file: For example: ...