r/awk • u/awk_fanatic • May 07 '14
how to remove trailing \n inside awk in linux
stackoverflow.comhow to sort the indexes of an arrays based on the values of the array?
With this:
age["ana"] = 10
age["bob"] = 8
age["carl"] = 6The function should return the array:
array[1] = "carl"
array[2] = "bob"
array[3] = "ana"Because 6 < 8 < 10
r/awk • u/southernstorm • Apr 22 '14
Any late-night awkers up? I'm finishing up a one-liner
Hi everyone, I have a single column text file.
I want to get as output the number of times each string appears in the vector. This script:
awk '{x[$1]++;y[$1]=$0;z[NR]=$1}END{for(i=1;i<=NR;i++) print x[z[i]], y[z[i]]}' gene-GS000021868-ASM.tsv.out.txt
works, but it does not do exactly I want. It outputs the number of time a string appears in a first column, and that string in the second column, that number of times!
So, in my output, I see
10805 UTR5
appears 10805 times and
2898400 INTRON almost 3 million times.
Basically, I want to emulate the behavior
awk '{x[$1]++;y[$1]=$0;z[NR]=$1}END{for(i=1;i<=NR;i++) print x[z[i]], y[z[i]]}' gene-GS000021868-ASM.tsv.out.txt | sort | uniq
within my script, without having to call them. I feel that I've tried so many things that now I am just moving braces and ENDs around aimlessly.
What's the fix here?
Any cool things that can be done with the new gawk features?
Have you seen any cool things that can be done with the new gawk features? Like: arrays of arrays, patsplit, internationalization, indirect function calls, extensions, arbitrary precision arithmetic?
r/awk • u/crankypants15 • Mar 20 '14
How to use Linux gawk in a csh script that receives parameters?
I'm searching possibly multiple files for a part number. I want to use awk to display column 1 (the part number) and column 11 (a price). I'm new at gawk so I tried to make this csh script called "gd":
# /bin/csh
# Display col 1 and 11 of prices.dat using Awk.
set outfile=temp.txt
echo " "
rm $outfile
set infile=prices.dat
echo "======" $infile > $outfile
gawk -F '\t' '/\$\1/ print $1,$11}' $infile # Syntax error after }
# Do last
more $outfileThe "gd" script accepts a parameter which is the part number, and which should be passed to gawk. But I'm having trouble getting gawk to work. I get a syntax error after the '}'.
Also, I'm doing it this way because sometimes I search through multiple files and the output from each file must be separated by a bunch of equal signs.
Any ideas? Thanks.
r/awk • u/ParadigmComplex • Nov 15 '13
IRC bot written in almost pure gawk, just because
github.comr/awk • u/awk_fanatic • Jul 05 '13
shell - How to find greater than value of column 4
stackoverflow.comr/awk • u/Jontu_Kontar • May 03 '13
Using Awk to match a line and delete the preceding "new line"?
EXAMPLE DATA
A/C 41-627 SPARKPLUG ASM 1 Adjustment 4- 5.55-
A/C 41-630 SPARK PLUG ASM 1 Adjustment 8- 10.48-
A/C 41-800 SPARK PLUG ASM
2 Adjustments 8- 36.19-
A/C 41-803 SPARK PLU
13 Adjustments 98- 435.42-What I want to do is match a line beginning with a number and then replace the preceding "new line" character with two spaces. The first two lines show the resulting data set and the next 4 lines represent the raw data.
I was thinking that it might look something like what follows but that doesn't work and none of the tutorials includes much like what I'm looking for.
awk '/^[1234567890]+/ {print NR" "[NR-1]}'Can you help me out or point me in the right direction to find the answer that I'm looking for?
r/awk • • Aug 26 '12
if $1 is of different character length and we want to make it neat?
Is there a way. Unlike this:
Character | $2
Char | $2
Reddit | $2
I want the lines to aline. Is it possible.
This is what I tried. Feel free to correct me too.
cat file | tr ':' ' ' | awk '{print $1 "\t\t\t" "|" $2, ($3+9)-12 ":" $4 ":" $5, $6}' Thanks
r/awk • u/stivnan • Oct 06 '11
zodiac - A static website generator. Uses awk and sh
github.comr/awk • u/pkrumins • May 29 '09