awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

1
vote
1answer
83 views

First line of awk output isn't what I expect

I am trying to figure out why a part of a file name disappears. In my case, I have created three files $ ls some-part-of-file.1 some-part-of-file.2 some-part-of-file.3 and when I use awk with FS ...
4
votes
3answers
174 views

How to only output lines that are younger than 3 months?

cat a.txt 1387111124 ./asfjlasdf.txt 1348681215 ./akdfyxcv.txt So I need this: cat a.txt | SOMEMAGIC 1387111124 ./asfjlasdf.txt The output should only have the lines that are younger than 3 ...
4
votes
3answers
559 views

Print a line only if the next line does NOT contain a particular match

I am trying to search a log file for logged activities that did not complete. For example, I log a "Starting activity for ID 1234..." and if successful, the next line will be "Activity 1234 ...
1
vote
2answers
205 views

Type URL and show HTTP status

I want to make a shell script where I type an url and it returns me the status code.So far I've tested wget is there any other cause it has the tendency to save whatever you run. Then I tried to some ...
0
votes
2answers
91 views

Format of SMTP headers for scanning inbox email

I am looking for a simple procedure to extract email from my inbox into a file for further processing, using e.g. awk. With "extract" I mean use e.g. regex to get emails with a particular subject. My ...
2
votes
1answer
51 views

awk - streamline this script

I have a text file. On odd number lines, it gives new dimensions of key elements of a building that I'm constructing. On even number lines, the old dimensions are given. My aim is to process this ...
0
votes
3answers
850 views

Shell script read separately columns from file

When we have file which is a kind of list like : Mary 34 George 45 John 56 Josh 29 using the awk command $1 refers to the first column and $2 to the second column.But once we write a shell script ...
-1
votes
2answers
129 views

How to manipulate output from commands with shell scripts [closed]

Simple question, having a ls -l command it makes a list on the command prompt and if we want to manipulate it we pipeline it with awk command, for instance if we want to to show specific files. Is ...
2
votes
1answer
45 views

Matching two different lines that are at least N lines distant from each other

I would like to match files that contain try (in one line) and consecutive catch (in another line) at least N lines later (to find very long try-catches and try to get rid of them). I mean, the first ...
1
vote
1answer
857 views

AWK how to add all columns beginning with specific row

I have this output: Count Process 238 0 1 1124027 1 1124065 1 1124066 1 1124069 1 1124072 1 1124073 1 1547365 1 1547366 I wanted to add all Count ...
3
votes
3answers
109 views

Print unique of who command

I want to show the online users using the who command but I want to have a unique output and not show any duplicates. I piped the output into awk but I am not very familiar with that, is this the ...
0
votes
2answers
184 views

bash script, printing multiple lines that matching to a specific patern

I have a log file and I'm making a script to do some actions. An action is to print a specific area of the log. Every block at the log starts with a specific time stamp and inside the block may have ...
2
votes
2answers
77 views

Convert numeric string from file to exit code in shell

I'd like to grep /etc/password for a username and return the last two digits of a user-id number as the return code. This is because I have an application whose main way of interacting with other ...
4
votes
5answers
292 views

Pattern matching across multiple lines

What is a quick and easy way to validate if the pattern "301 domaname.com 200" is present within BASH when spread across multiple lines of output? I was using something like the following: awk ...
2
votes
1answer
69 views

gawk with gawkextlib

In my system (Slackware64-14.1) gawk is installed in version 4.1.0. I'd like to install gawkextlib to have access to some of its features, namely xml. From the README file of gawkextlib-0.4.9: ...
2
votes
1answer
363 views

Getting data section with maximum element

I have some data stored in JSON-like format. { { value1: 14, value2: 12, value3: 1 }, { value1: 4, value3: -1 } } How can I get subsection ...
5
votes
2answers
83 views

Adding corresponding Numbers in a Range

I have a dataset with 30000 lines. I want to add all the corresponding values (i.e. Column 2) between the range 0-50 and then 50.1-100 and then 100.1-150 etc. (presented in column 1), and this ...
8
votes
5answers
6k views

Remove comma between the quotes only in a comma delimited file

I have a input file delimited with commas (,). There are some fields enclosed in double quotes that are having a comma in them. Here is the sample row 123,"ABC, DEV 23",345,534.202,NAME I need to ...
0
votes
0answers
235 views

gsub command in awk [duplicate]

I am trying to replace the field separator from "," to "|" except for the strings which are under double quotes " " . The following command works fine : awk -F\" '{for(i=1;i<=NF;i+=2) ...
3
votes
1answer
47 views

Automatically load a user function at startup with awk?

I guess this answer from awk separator preferences already gives a hint, but I thought I'd ask explicitly: Is there an equivalent to a .bashrc file for awk, where I could define my own library ...
-2
votes
1answer
45 views

delete first two line in awk script [closed]

How can I delete the first two line in awk script? From blabla blala 1 2 3 4 To 1 2 3 4
4
votes
2answers
61 views

Concatenating fields from lines with different numbers of fields

Given input like this: x y a b c t p q w w t a b c d p q r I'd like to concatenate fields from field 3 up to but not including the last one. If field 3 is the last field, I'd like to insert a ...
5
votes
3answers
200 views

removing redundancy from output columns

What is a *NIX way of removing redundancy in a case where I have pairwise comparisons like these in two columns A B B A A C A D C A D A B C C B A B and B A ...
1
vote
2answers
98 views

using awk to create a LaTex table from my data in a text file

So I have used awk a few times to add or remove text from each line of a text file. What I would like to learn how to do now is to add some characters to each line in multiple places. What this is ...
3
votes
3answers
159 views

awk read error bad address

I have a file that is roughly 30GB. I am using, awk ' $1 <= 2000 ' myfile.txt >> myfile_new.txt But, I get this error after a while - awk: read error (Bad address) I guess this is ...
3
votes
1answer
30 views

How to calculate (weighted) majority over columns?

I have two files: the first one contains lines where the first column is an ID, and the remaining columns are votes, e.g. 3242 -1 1 -1 1 1 1 In a first step I want to calculate the majority for ...
1
vote
2answers
52 views

Replace “-from” with “this” in the begining of line

I want to replace "-from" with "this" in the begining of line. This should happen when that line has 'R' at the end and line above it has "D" at the end. For example for the block shown below: ...
4
votes
3answers
93 views

awk separator preferences

I write ad hoc awk commands in cygwin to process tab delimited files. Pretty much every command starts with: BEGIN {FS="\t";OFS="\t";ORS="\r\n";} How can I make these separators the default to ...
2
votes
2answers
1k views

Insert text in specific lines of a file?

How can insert some text in specific lines of a file? What is most simplest method that I can use? (bash, sed, awk?) What I want to do, might be simple, but I don't know where I should start. It's ...
4
votes
2answers
140 views

How can I round all numbers in a file?

How can I round all numbers in a file that countains several columns of numbers up to a certain precision? Can this be done with awk? A single line looks like this: text - 0.1655456615 - 0.158645 - ...
2
votes
6answers
221 views

Remove lines that do not start with a pattern from a given set of patterns

I have a file that contains data like this: report aaaaaaaa - .. -th bbbbbbbbb -to ccccccccc .. --. Question: I want to remove any line that does not start with following strings : report ...
2
votes
1answer
76 views

replace text after match

aaaaaaaaa bbbbbbbbb -th ccccccccc_RD \ DDDDDDDD FFFFFFFF -th GGGGGGG_RD \ using sed/grep/awk etc, In the above text, if a line ends with "RD \" , replace "-th" with "-to" at the ...
1
vote
2answers
323 views

How to sum a bash array of numbers (some in scientific notation)?

Since the following command using bc does not work for numbers in scientific notation, I was wondering about an alternative, e.g. using awk? sum=$( IFS="+"; bc <<< "${arrValues[*]}" )
1
vote
1answer
94 views

Insert a space before the first comma in a csv file

I have a huge CSV file which contains 100000 rows. However, I need to do some processing and so for that I need to have a single space before the first comma. My current data is something like below. ...
1
vote
3answers
324 views

Using sed/awk to remove anything after first space

aaaaaaaa 09 bbbbbbbb 90 ccccccccccccccc 89 ddddd 09 Using sed/awk/replace, in the above text I want to remove anything that comes after the first space in each line. For example the output ...
3
votes
1answer
150 views

grep on line before the match plus the match

zzzzzzzzz aaaaaaaaa bbbbbbbbb & ccccccccc & ddddddddd hhhhhhhhh eeeeeeeee fffffffff & ggggggggg & in the above line, what i want is to grep/sed/awk (any method is fine) line that ...
3
votes
2answers
694 views

What is the best way to find a list of several strings within a large text file

The short, general question is: In Unix/Linux, what is the best way to find a list of several (about 150) strings within a large text file? I am asking this to all Unix/Linux experts as a general ...
-2
votes
1answer
225 views

Search low values in mainframe files

I am working with mainframe files and it seems that the low values (x'00') exists in the records in the file which throws off my import for fixed block. Does anyone know how to eliminate those ...
0
votes
1answer
219 views

Awk with multiple delimiters

I am trying to execute awk on something like this : <tag x="whatever" y="http://mysite.com/somewords/word1/word2/word3/word4"> I would like to extract word2 which comes forever after word1, ...
1
vote
2answers
59 views

How can I reformat tabular data using AWK?

I have a file contain following output. ora.abc.db 1 ONLINE ONLINE serverA Open 2 ONLINE ONLINE serverB Open ora.xyz.db 1 ...
4
votes
3answers
251 views

using awk to split a line on single spaces not multiples

I'm trying to split a line that I have no control over the format of. If parameter 7 and 8 are missing which is possible they will be replaced by a space so I would end up with, field1 field2 field3 ...
4
votes
1answer
97 views

Matching Five Columns in two Files using Awk

I have two Input files. File1: s2/80 20 . A T 86 F=5;U=4 s2/20 10 . G T 90 F=5;U=4 s2/90 60 . C G 30 ...
2
votes
3answers
513 views

How can I turn ugly output into pretty, useful information?

How can I turn this ugly output into pretty, useful data? The output: /* ---------- TA#box#AbC_p ---------- */ insert_job: TA#box#AbC_p job_type: a #owner: bob permission: gx date_conditions: 1 ...
2
votes
4answers
388 views

Can awk use field identifiers also for shell strings (variables)?

Well, this apparently is not possible the way I'm trying it. This alternate approach to obtain bar as a resulting string works, though: #!/bin/bash path1=/usr/tmp/foo/bar/baz awk -F/ '{print $5}' ...
4
votes
5answers
1k views

extract fields from “tail -f” of a syslog stream

Example line from syslog file: Aug 1 10:25:50 10.10.10.1 id=firewall sn=XXXX time="2012-08-01 14:35:18 UTC" fw=x.x.x.x pri=6 c=1024 m=537 msg="Connection Closed" f=11 n=195273698 ...
3
votes
4answers
209 views

How to Prefix a column values with an apostrophe ( ' )?

I have a CSV file with multiple columns and 1000's of records, I need to prefix all the values of one of the columns (lets say 2nd column) with an apostrophe ' except in the first line or header line, ...
5
votes
2answers
128 views

Distributing a script: Should I use /bin/gawk or /usr/bin/gawk for shebang?

Is gawk in /bin or /usr/bin usually? I would go with #!/usr/bin/env gawk but then I can't use arguments. Right now I'm using #!/bin/gawk -f. The script is very long and contains a lot of single ...
0
votes
2answers
90 views

why does `awk` fail when I put it in a bash script

on the prompt: ls | awk '{printf("%s\t\t%s\n", $9, $3);}' succeeds in printing what it is supposed to be printing. If I put it in a file, I get four or five empty lines (about the number of lines ...
2
votes
3answers
1k views

Multiple pattern match and print in single line

I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line. ...
4
votes
5answers
181 views

Multi-line grep beween two tags, only show the last match

I'm having a program that intermingles data segments into log output: log message log message ----BEGIN INLINE DATA---- data data data -----END INLINE DATA----- log messge I'm looking for something ...