awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

3
votes
2answers
337 views

Truncate a file on a certain pattern

How would I go about truncating a binary file when a certain pattern is found? For instance, I want to truncate the file at the first occurrence of the pattern 0xFFFFFFFF. I think something like awk ...
2
votes
3answers
3k views

Extracting tokens from a line of text

Using bash scripting and grep/awk/sed, how can I split a line matching a known pattern with a single character delimiter into an array, e.g. convert token1;token2;token3;token4 into a[0] = token1 … ...
3
votes
2answers
613 views

Using grep/sed/awk to classify log file entries

I need to process a very large log file with many lines in different formats. My goal is to extract unique line entries who have the same starting pattern, e.g. '^2011-02-21.*MyKeyword.*Error', ...
2
votes
2answers
1k views

How to build a long command string?

I've a sequence of commands to be used along with lot of pipings, something like this: awk '{ if ($8 ~ "isad") {print $2, $5, "SE"} else {print $2, $5, "ANT"} }' ...
0
votes
2answers
1k views

How to run a shell script containing an awk command

How to run this script (called count.sh)? awk 'BEGIN{ x=0 ; while (x < 5) { x+=1 ; print x ; } }' I'm trying to run it with sh count.sh but it's giving me an error.
14
votes
9answers
2k views

There must be a better way to replace single newlines only?

I am in the habit of writing one line per sentence because I typically compile things to LaTex, or am writing in some other format where line breaks get ignored. I use a blank line to indicate the ...
3
votes
1answer
6k views

Filtering on dates with grep and awk

I have created the alias below in my .bash_aliases file alias auth="grep \"$(date|awk '{print $2,$3}')\" /var/log/auth.log | grep -E '(BREAK-IN|Invalid user|Failed|refused|su|Illegal)'" ...
5
votes
3answers
738 views

extracting “tag” information from git with a shell script

The vc bundle is a neat little package that extracts information about a git repo for easy insertion into a LaTeX document. It doesn't currently extract information about whether the current commit is ...
6
votes
3answers
2k views

AWK: wrap lines to 72 characters

$ awk 'length > 72' {HOW TO PRINT THE LINEs IN PCS?} msg ie I want it to add \n after 72 chars and continue, so initially you may need to remove all single \ns and the add them. It may be easier ...
5
votes
4answers
224 views

How could I simplify this command to only use awk?

awk '/user/ {print $1 }' /etc/userdomains | sed 's/://' the format of /etc/userdomains is domain.tld: user otherdomain.tld: otheruser
53
votes
6answers
13k views

Is there a basic tutorial for grep, awk and sed?

I've been a Linux user for a while, and I've a pretty decent understanding of most the common command line utilities. However, ones that come up and up again in relation to programming are grep, awk, ...
16
votes
9answers
8k views

Tool in UNIX to subtract dates

Is there any tool in Solaris UNIX (so no GNU tool available) to subtract dates? I know that in Linux we have gawk that can subtract one date from another. But in Solaris the maximum we have is nawk ...
8
votes
6answers
234 views

Grab certain contents of a file

So I know tools exist for this problem because I've heard about them, but I don't know what they are. I want to do something like filter out all data but the usernames in /etc/passwd. For example, I ...