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
637 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
229 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
388 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
751 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
124 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
816 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
343 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
450 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
574 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
252 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
335 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
835 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
215 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
723 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
304 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
456 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
263 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
838 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
968 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
90 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 ...
0
votes
0answers
567 views

awk+regex with GUI on windows?

Sometimes i have text copied from a doc or a browser which i need to process. I figure awk would solve it and maybe a little regex to help. Is there something like this? or do i need to find a ...
0
votes
2answers
1k views

Add a newline after each XML tag

My xml file looks like this: <price = "2.22"><instock = "1"> I need to have it like that: <price = "2.22"> <instock = "1"> After each ">" character I need to put a ...
5
votes
1answer
4k views

Awk doesn't work when inside double quotes

This command doesn't work: ssh $HOST "ls -l | awk '{print $1}'" Above ignores the command "awk" I think it might be because of the double quotes? Also, how would I add another set of double quotes ...
5
votes
1answer
1k views

How to split binary file based on pattern?

I would like to split a binary file into smaller files based on pattern 'xÚ' (it's 78 DA in hexadecimal), so when there's an 'xÚ' in the file the splitter script splits and pastes the content into a ...
2
votes
2answers
212 views

change the number format

Hello I have a lot of lines like below: 123;XXXXXXXXXXXXXXX;ABCDE;YYYYYYYY;08082010;000000000000000;03/08/10;110000;ZZZZZZZZZZZZZZZZZ;0002 I just want to change the number format (15 digit) ...
0
votes
2answers
84 views

Linux file content replacement issue

I am using Linux Red Hat 5 Enterprise version. For all files in the current directory, I want to replace all occurrences of /foo/goo/zoo (which are contained in file contents) to /a/b/c. Any ideas ...
0
votes
2answers
459 views

awk + match string after “=” seperator

I have problem with the following awk syntax echo " param1 param2 param3 = param1 AA , AB , AC , AD " | awk -F"=" '$2~/AA|AB|AC|AD/{print "passed"}' the awk print passed , but its not shuld ...
1
vote
3answers
778 views

csv averages on linux command line

Hey I have a big file full of records like this 1, 2, 4, 5, 6 1, 3, 5, 6, 3 1, 4, 5, 6, 6 2, 4, 5, 5, 5 2, 3, 4, 5, 2 anyway i need to take the average of all rows with the same 1st number(key). ...
2
votes
2answers
501 views

bash script-fu, way to get text from middle of output (random spots)

So basically, i'm trying to get the rating from an mp3 programattially, and using the command line tool id3v2, I can get the rating that my program puts it into: $ id3v2 -R Drake\ -\ Over3.mp3 id3v1 ...
0
votes
8answers
236 views

Unix command to list the portion of the end of a log file from a line containing only hyphens to end of file

I have a long log file where each entry begins with a line containg only hyphens.
0
votes
2answers
262 views

awk + verify field if zero

hi all To find if field 5 has I use the: [[ -z ` echo $LINE | awk '{print $5}' ` ]] my question if there is another elegant way to verify if field 5 is zero? THX Yael
0
votes
1answer
798 views

Solaris bash script / search and append field to end of line in /etc/group

I need a bash script that will modify /etc/group to append and delete NIS users to specific local groups on a Solaris 10u8 system. Preferable one or two functions with uid and groupname as varibles. ...
7
votes
6answers
948 views

Joining text files with 600M+ lines

I have two files, huge.txt and small.txt. huge.txt has around 600M rows and it's 14 GB. Each line has four space separated words (tokens) and finally another space separated column with a number. ...
3
votes
2answers
4k views

replace nth occurence of string in each line of a text file

I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe. What's the best way to go? Using sed I was ...
5
votes
4answers
3k views

SQL like group by and sum for text files in command line?

I have huge text files with two fields, the first is a string the second is an integer. The files are sorted by the first field. What I'd like to get in the output is one line per unique string and ...
2
votes
4answers
7k views

grepping a substring from a grep result

Given a log file, I will usually do something like this: grep 'marker-1234' filter_log What is the difference in using '' or "" or nothing in the pattern? The above grep command will yield many ...
0
votes
3answers
249 views

How to use sed or AWK to separate a string (NOT string in files)

How can I separate .sh files into a list? I have tried: ls *.sh | xargs sed 's/\n/ /g' > out.txt The return of ls *.sh is a long string with '\n' in the middle.
0
votes
3answers
2k views

how to use grep, sed, and awk to parse tags?

I want to write a script that finds a open/close tag pair in a text file and prepends a fixed string to each line between the pair. I figure I use grep to find the tag line numbers and either awk or ...
7
votes
5answers
3k views

awk, mawk, nawk, gawk… WHAT?

I've just started learning awk and I'm a little confused about all those versions around. Is there any "version" which is found on all Unix-like systems? Like, you know, plain vi? Does the standard ...