awk

Problem with replace command

I have some problem with replace command. Input file i have this {a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]} I want to replace with single quotes '{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}' Using the below mentioned command find input.txt -exec sed 's/{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}/'{a[$1]=a[$1]FS$2}END{f...

How to replace catch block in *.java using sed ?

How to replace the following pattern in a java project catch(SQLException e) { \\TO DO } with catch(SQLException e) { S.O.P(); } Please note that the file will have other patterns like catch(IOException e) { // To Do } which should not be changed. I tried sed 's/catch\(SQLException[^\}]*}/catch(SQLException e)...

Awk conditional sum from a CSV file

I have a CSV file from which I would like to extract some pieces of information: for each distinct value in one colum, I would like to compute the sum of the corresponding values in another column. Eventually, I may do it in Python, but I believe there could be a simple solution using awk. This could be the CSV file: 2 1:2010-1-bla:...

Print columns with Awk or Cut?

I'm writing a script that will take a filename as an argument, find a word a specific word at the beginning of each line - the word ATOM, in this case - and print the values from specific columns. $FILE=*.pdb * if test $# -lt 1 then echo "usage: $0 Enter a .PDB filename" exit fi if test -r $FILE then grep ^ATOM $FILE | awk '{ print ...

AWK/BASH: how to match a field in one file from a field in another?

Hi all, I have 2 files, the first contains the following: ... John Allen Smith II 16 555-555-5555 10/24/2010 John Allen Smith II 3 555-555-5555 10/24/2010 John Allen Smith II 17 555-555-5555 10/24/2010 John Doe 16 555-555-5555 10/24/2010 Jane Smith 16 555-555-5555 9/16/2010 Jane Smith 00 555-555-5555 10/24/2010 ... and the second fil...

AWK/SED remove columns that contain parenthesis

Hi all, I was wondering if it would be possible to remove columns within a data file that contain any parenthesis that can be contained in ANY column. For example ... John Doe (Tech Department) 09/12/2009 555-555-5555 Jane Smith 09/12/2009 555-555-5555 (Suspended) Alfred doe 555-555-5555 (Vacation) 09/09/2011 ... So then I would like...

AWK program to find the average rainfall of three states

I want to find the average rainfall of any three states say CA, TX and AX for a particular month from Jan to Dec . Given input file delimited by TAB SPACES and has the format city name, the state , and then average rainfall amounts from January through December, and then an annual average for all months. EG may look like AVOCA PA 3...

print everything up to match in pattern

I have a data set that looks like the following: movie (year) genre for example. some words (1934) action My goal is to grab each "movie" field and then check a different file that also has a bunch of movies and delete the lines from the second file that do not contain the movie. I have been trying to use awk to do this, but have o...

AWK/BASH: How to remove duplicate rows from file with known field range?

Hi all, I was wondering if there was a way to use bash/awk to remove duplicate rows based on a known field range. For example: Easy Going USA:22 May 1926 Easy Going Gordon USA:6 August 1925 Easy Life USA:20 May 1944 Easy Listening USA:14 January 2002 Easy Listening ...

Could a bored AWK master kindly convert this Python program?

I love Python but do not really care for AWK. For purposes of comparison (and to see how a Python-to-AWK master would do this), could someone rewrite the following Python program in AWK? Considering how short it is, some would think that the rewrite would be simple and easy for anyone with a little time. import os ROOT = '/Users/Zero/D...

shell script to parse log file

Hi, I am given a log file(see below), I need to make it to this format using bash script: title pdfspool date rip date bmpspool date CLAB date Sometitle12 10/09/23 00:56:40 10/9/23 0:56:46 10/9/23 0:56:50 10/9/23 1:01:13 log file !!Begin Source aserver:pdf_spool:the, Job 844b015e0043469e, Inst 844b015e0043469e T...

Regarding grep command

I have two queries I do a grep and get the line number of the input file. i want to retrieve a set of lines before and after the line number from the inputfile and redirect to a /tmp/testout file. how can i do it. I have a line numbers 10000,20000. I want to retrieve the lines between 10000 and 20000 of the input file and redirect ...

shell to filter prohibited words on a file

Good day shell lovers! basically i have two files: frequency.txt: (multiple lines, space separated file containing words and a frequency) de 1711 a 936 et 762 la 530 les 482 pour 439 le 425 ... and i have a file containing "prohibited" words: stopwords.txt: (one single line, space separated file) au aux avec le ces dans ... so ...

Concatenate Lines in Bash

Most command-line programs just operate on one line at a time. Can I use a common command-line utility (echo, sed, awk, etc) to concatenate every set of two lines, or would I need to write a script/program from scratch to do this? $ cat myFile line 1 line 2 line 3 line 4 $ cat myFile | __somecommand__ line 1line 2 line 3line 4 ...

converting IP ranges into discrete ip numbers using bash/awk/sed

I am processing IP source/destination/port lists created as acl requests The request looks some thing like this: source IP destination IP Port 76.211.12.9 10.112.12.232 1521 The Source and destination IP's have three distinct formats x.x.x.x,y,z x.x.x.x-z x.x.x.x,y.y.y.y,z,z,z,z I want to create output x.x.x.x x.x.x.y x.x...

problem with awk print

Hi guys I want to print in awk line and character ' after the line, but awk put the character in the middle of the line. Here is my code : awk -v d="'" {print $0 d} i am using bash2 thanks for help ...

Passing output from one command as argument to another

Hello, I have this for: for i in `ls -1 access.log*`; do tail $i |awk {'print $4'} |cut -d: -f 1 |grep - $i > $i.output; done ls will give access.log, access.log.1, access.log.2 etc. tail will give me the last line of each file, which looks like: 192.168.1.23 - - [08/Oct/2010:14:05:04 +0300] etc. etc. etc awk+cut will extract the dat...

Printing first four lines per key

Dear all I would like to print the first 4 lines by field 1 using awk Input 111 1032192 111 2323476 111 1698881 111 2451712 111 2013780 112 2331004 112 1886376 112 1189765 112 1877267 Output 111 1032192 111 2323476 111 1698881 111 2451712 112 2331004 112 1886376 112 1189765 112 1877267 Thanks Tony ...

print all rows following matched row

How can I print all rows after matching pattern in nth row, but ignore all before matched row including the matching row, here is an example : row1 something in this row row2 something in this row row3 something in this row row4 don't need to match the whole line, something like java String.contains() row5 something in this row row6 som...

How to get only last IP from one or many divided by comma on beginning of the line

Hi, I would like to parse log files, I need to get only last IP from one or many divided by comma on beginning of the line: This is how the lines look like: 80.250.5.1 - - [26/Oct/2010:13:10:14 +0200] ... 80.250.5.1, 80.250.5.2 somethingA - [26/Oct/2010:13:10:14 +0200] ... 80.250.5.1, 80.250.5.2, 80.250.5.3 - somethingB [26/Oct/2010:1...