awk

Replacing all the numbers with their currency format in given line of text

I want to write a Shell (AWK, Sed also fine) program to take as a input a SINGLE line of text. Which will have arbitrarily spread integer strings in it. e.g "12884 and 111933 are two numbers and 323232 is also a number" I want the output to be "12,884 and 1,11,933 are two numbers and 2,23,232 is also a number" If this was PHP a sim...

Bash scripting call to AWK

I'm having difficulty getting the awk command inside a bash script to work. The script follows: #!/bin/bash fpga-test -1 -a $1 > tmp.file && awk \'\/Read\/ {print \$2}\' tmp.file When I run the command I get the following error. # my_script 14 awk: cmd. line:1: Unexpected token The intermediate file (tmp.file) looks like this, an...

Summing up two columns the Unix way

# To fix the symptom How can you sum up the following columns effectively? Column 1 1 3 3 ... Column 2 2323 343 232 ... This should give me Expected result 2324 346 235 ... I have the columns in two files. # Initial situation I use sometimes too many curly brackets such that I have used one more this { than this } in my f...

What's what awk can't that sed can?

Or just a matter of choice and call awk and sed equivalent towards usage. They both do the common search replace seemingly identically regarding i/o. ...

Using Awk to process a file where each record has different fixed-width fields.

I have some data files from a legacy system that I would like to process using Awk. Each file consists of a list of records. There are several different record types and each record type has a different set of fixed-width fields (there is no field separator character). The first two characters of the record indicate the type, from thi...

Problem with Awk & Grep

I like to get window pid (only firefox) from wmctrl, i tried wmctrl -lp | grep Firefox | awk -F" " "{print $1}" but output not match my expect. Help please. beer@beer-laptop# wmctrl -lp 0x0160001b -1 6504 beer-laptop x-nautilus-desktop 0x016000bd 0 6504 beer-laptop conference - File Browser 0x03e00003 0 0 N/A XBMC Me...

Extracting first two characters of a string (Shell Scripting)

Hi all - I'm new to sed and awk - so I'm not really sure which is the most efficient way to go about this. I'm looking to extract the first two letters of a string. I could do it if they were going to be same every time, but I can't seem to figure out how to just say, Take n positions of this string from this larger string x. IE. US...

Invoking a script, which has an awk shebang, with parameters (vars)

I have an awk script that I have defined thusly: #!/usr/bin/env awk BEGIN { if (!len) len = 1; end = start + len } { for (i = start; i < end; i++) { print $1 } } I have saved it as columns and chmod +x'd it. I want invoke it so that start and end are defined as it traverses over a file. I was thinking this should work: cat some_file ...

How to search for a pattern inside a file and delete the lines in Unix on the command line?

I need to search for a pattern in files. For example the content of the file is below: 3555005!K!00630000078!C!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078! 3555005!K!204042880166840!I!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078! 3555005!D!16042296!DUMMY...

awk gives the following error

"awk: Function systime is not defined." but systime is a built in command ...

Delete a line with a pattern

Hi I want to delete a line from a file which matches particular pattern the code I am using is BEGIN { FS = "!"; stopDate = "date +%Y%m%d%H%M%S"; deletedLineCtr = 0; #diagnostics counter, unused at this time } { if( $7 < stopDate ) { deletedLineCtr++; } else ...

Awk script to get time averages

I have a file with timestamps in the format: HH:MM:SS.MS e.g. 00:04:02.08 00:04:01.08 Each timestamp is on a different line, usually just two lines in a file I need to write an awk script to calculate average of these times. I am quite naive in awk scripting, so if someone can please give me a code-snippet, it will a lot of...

Generic awk script to calculate average on any field through command line argument

Hi, I want to write a generic awk script that can take as input a file and a field number (in that file) and give me the average value of that field in that file. I would use it something like this: bash$ avg.awk 3 input.file 22 bash$ avg.awk 4 input.file 2001 Of course, I can write the script if I know which field (e.g., $3) I am go...

How can I delete duplicate lines in a file in Unix?

Is there way to delete duplicate lines in a file in Unix? I can to it with sort -u and uniq commands. but I want to use sed or awk. Is that possible? ...

how do you parse comma-separated-values (csv) with awk?

I am trying to write an awk script to convert a CSV formatted spreadsheet into XML for Bugzilla bugs. The format of the input CSV is as follows (created from an XLS spreadsheet and saved as CSV): tag_1,tag_2,...,tag_N value1_1,value1_2,...,value1_N value2_1,value2_2,...,value2_N valueM_1,valueM_2,...,valueM_N The header column represe...

awk '{print $9}' the last ls -l column including any spaces in the file name.

How would I get awk to output $9 $10 $11 etc as some of my files have spaces in them. ls -l | grep ^- | awk '{print $9}' ...

Extract Data from CSV in Bash script (Sed, AWK, Grep?)

I need to extract some data from a CSV file. The CSV is a 2 column file with multiple records. The first column is the date, the second column is the data that needs to be extracted. The first row of the CSV file is the column headers, so it can be skipped. And I've already created the column header for the extracted data's csv file,...

Awk pattern matching

I want to print userId = 1234 userid = 12345 timestamp = 88888888 js = abc from my data messssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss <input name="userId" value="1234" type="hidden"> messsssssssssssssssssss <input name="userid" value="12345" type="hidden"> messssssssssssssssssss <input name="timestamp" valu...

How can I make the list of letters from A to Z and iterate through them in the shell?

Say I want to iterate from letter A to letter Z in csh shell. How do I succinctly do that? In bash I would do something like for i in 'A B C ...Z'; do echo $i; done The point is I don't want to write A through Z, I want something like [A-Z] Can you suggest a one line suggestion in AWK or Perl? ...

using OR in awk

I use the following two commands to see my tables from binlogs. mysqlbinlog mysql-bin.000016 | awk '/session/,/;/' | more mysqlbinlog mysql-bin.000016 | awk '/session_log/,/;/' | more How do I see both the table lines in a single statement? ...