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
2answers
403 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
331 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
280 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
3k 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
4k 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
411 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
357 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
598 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
692 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
717 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
171 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
909 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
675 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
240 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
412 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
859 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
127 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
882 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
376 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
492 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
618 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
439 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
267 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
8k 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
349 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
874 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
235 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
767 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
316 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
481 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
3k 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
8k 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
268 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
910 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: ...
1
vote
3answers
2k views

Passing a shell script variable into an AWK command

I want to be able to call a shell script contining the following command. awk -F $'\xE7' '{OFS ="¬"} { $3 = sprintf("%010s". $3) ; print $0 }' > outputfile But I want to be able to pass a shell ...
1
vote
2answers
4k views

How can I zero pad a particular field in a text file?

I have a file like this: 123123213,456,be 124243233,4346,ytr 123123123,436535,uytr 324234324,322,yt 234324323,32,tyutr I want to zero-pad the middle field to give the result: 123123213,00000456,be ...
3
votes
2answers
1k views

Increment one value in a text line, using script

I have a text file as input. I need to filter that through some program, SED, AWK, whatever, where i need to increment a value in a particular line every time i run the script. What's the best way ...
1
vote
1answer
91 views

awk + add rules to awk command

I have the following awk command awk '{if ( $2 == "x.name" ) {print "OK"} else {print "NOT OK" } }' but $2 could be x.name or x-name or x:name how to change the following awk in order to ...