Dataset Viewer
Auto-converted to Parquet Duplicate
id
stringlengths
10
14
request
stringlengths
37
423
program
stringlengths
11
336
input_text
stringlengths
8
422
expected_output
stringlengths
2
1.2k
validation_input
stringlengths
7
308
validation_output
stringlengths
2
252
family
stringclasses
1 value
difficulty
int64
3
3
split
stringclasses
1 value
source
stringclasses
3 values
license
stringclasses
1 value
question_url
stringlengths
71
125
question_title
stringlengths
27
91
question_owner
stringlengths
3
15
answer_owner
stringlengths
3
20
answer_id
int64
1.07M
80M
question_score
int64
6
914
paraphrase_of
stringlengths
10
11
⌀
paraphrase_model
stringclasses
1 value
so-1068650
Write an awk program that removes the UTF-8 Byte Order Mark (BOM) from the beginning of the first line of input. The BOM consists of the bytes EF BB BF. If the first line starts with these characters, remove them. Print all lines.
NR==1{sub(/^\xef\xbb\xbf/,"")}1
Hello World Second Line Third Line
Hello World Second Line Third Line
No BOM Here Another Line
No BOM Here Another Line
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/1068650/using-awk-to-remove-the-byte-order-mark
Using awk to remove the Byte-order mark
Boldewyn
Bartosz
1,068,700
107
null
null
so-11952854
Write an awk program that reads lines from stdin. For each line, split the fields by whitespace. For each field, if it contains an '@' character, split it into a key and a value using '@' as the delimiter. If the resulting value part is empty or consists only of spaces, replace the value with 'Y'. Print the modified ke...
{ for (i = 1; i <= NF; i++) { if (index($i, "@") > 0) { n = split($i, parts, "@") key = parts[1] val = "" for (j = 2; j <= n; j++) { if (j > 2) val = val "@" val = val parts[j] } if (val ~ /^[[:space:]]*$/) { val = "Y" } print key "=" val ...
user@john admin@ host@server1 config@ data@value
user=john admin=Y host=server1 config=Y data=value
a@ b@ c@d e@f
a=Y b=Y c=d e=f
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/11952854/how-to-check-if-the-variable-value-in-awk-script-is-null-or-empty
How to check if the variable value in AWK script is null or empty?
samarth
Levon
11,952,924
64
null
null
so-11967776
Swap the first and second fields of each line in the input, preserving the rest of the line exactly as it is. Assume fields are separated by whitespace.
{ temp = $1; $1 = $2; $2 = temp; print }
Affy-id chr 0 pos NA06984 Col1 Col2 Rest of line
chr Affy-id 0 pos NA06984 Col2 Col1 Rest of line
A B C D E First Second Third
B A C D E Second First Third
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/11967776/swap-two-columns-awk-sed-python-perl
Swap two columns - awk, sed, python, perl
Charley Farley
perreal
11,967,849
83
null
null
so-12204192
Extract the third path component, the fifth path component, and the value after the equals sign from each line. Use forward slashes and equals signs as delimiters.
BEGIN { FS = "[/=]" } { print $3, $5, $8 }
/logs/tc0001/tomcat/tomcat7.1/conf/catalina.properties:app.env.server.name = demo.example.com /logs/tc0001/tomcat/tomcat7.2/conf/catalina.properties:app.env.server.name = quest.example.com
tc0001 tomcat7.1 demo.example.com tc0001 tomcat7.2 quest.example.com
/data/projA/src/main/java/App.java:version = 1.0.0 /data/projB/lib/utils/helper.py:mode = production
projA main 1.0.0 projB utils
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/12204192/using-multiple-delimiters-in-awk
Using multiple delimiters in awk
Satish
embedded.kyle
12,204,350
306
null
null
so-12297859
Write an awk program that reads lines from stdin. For each line, extract and print only the text that appears after the last colon character. If a line does not contain a colon, print the entire line unchanged.
{idx=match($0, /:[^:]*$/); if(idx>0) print substr($0, idx+1); else print $0}
TF_list_to_test10004/Nus_k0.345_t0.1_e0.1.adj:PKMYT1 path/to/file:GENE_A no_colon_here
PKMYT1 GENE_A no_colon_here
server:port:service_name simple_line key:value
service_name simple_line value
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/12297859/remove-all-text-before-colon
Remove all text before colon
NewUsr_stat
Sacha Epskamp
12,297,934
77
null
null
so-13046167
Print the last field of every line that contains the string 'A1'.
/A1/ {print $NF}
A1 123 456 B1 234 567 C1 345 678 A1 098 766 B1 987 6545 C1 876 5434
456 766
A1 foo bar X1 ignore this A1 baz qux Y1 skip me
bar qux
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/13046167/printing-the-last-column-of-a-line-in-a-file
Printing the last column of a line in a file
Rayne
Olaf Dietsche
13,046,224
201
null
null
so-1444406
Remove duplicate lines from the input text while preserving the order of their first occurrence.
!seen[$0]++
apple banana apple cherry banana date
apple banana cherry date
line1 line2 line1 line3 line2 line4
line1 line2 line3 line4
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/1444406/how-to-delete-duplicate-lines-in-a-file-without-sorting-it-in-unix
How to delete duplicate lines in a file without sorting it in Unix
Vijay
Jonas Elfstr&#246;m
1,444,448
214
null
null
so-14462529
Extract the first 22 characters from each line of the input text.
{ print substr($0, 1, 22) }
000000000001199998000180000 DUMMY RAG # MFR NOT ST 1999980 ZZ- 0 0 0ZZ- 000000000002199998000180000 DUMMY RAG # MFR NOT ST 1999980 ZZ- 0 0 0ZZ-
0000000000011999980001 0000000000021999980001
ABCDEFGHIJKL1234567890EXTRA Short
ABCDEFGHIJKL1234567890 Short
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/14462529/how-to-get-first-n-characters-of-each-line-in-unix-data-file
How to get first n characters of each line in unix data file
Teja
Chris Seymour
14,462,614
82
null
null
so-14739057
Print the third field of each line where the eighth field is exactly equal to the string "ClNonZ".
$8 == "ClNonZ" { print $3 }
2 14 0.180467091 0.800424628 0 0.0566 0.0103 ClNonZ 5 22 0.010615711 0.959660297 0.010615711 0.0476 0.0061 ClNonZ 9 31 0.492569002 0.350318471 0.138004246 0.0485 0.0088 ClNonZ
0.180467091 0.010615711 0.492569002
1 11 0.959660297 0 0.021231423 -0.0073 -0.0031 MhZisp 3 19 0.98089172 0 0 -0.0158 0.0124 MhNonZ 2 14 0.180467091 0.800424628 0 0.0566 0.0103 ClNonZ
0.180467091
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/14739057/using-awk-with-column-value-conditions
using awk with column value conditions
user1687130
Rob Davis
14,739,101
137
null
null
so-1506521
Print the third field of the fifth line of the input.
NR==5{print $3; exit}
Line1 F1 F2 F3 F4 Line2 F1 F2 F3 F4 Line3 F1 F2 F3 F4 Line4 F1 F2 F3 F4 Line5 F1 F2 TargetValue F4
F2
A B C D E 1 2 3 4 5 a b c d e x y z w v p q r s t
r
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/1506521/select-row-and-element-in-awk
Select row and element in awk
Tim
Dennis Williamson
1,506,601
108
null
null
so-15681498
Calculate the average of all whitespace-separated numbers found in the input text stream. Output the result in the format 'ave: <value>' with default floating point precision.
{s+=$1} END{if(NR>0) print "ave:", s/NR}
1.00 1.23 54.4 213.2 3.4
ave: 1
10 20 30
ave: 10
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/15681498/scripts-for-computing-the-average-of-a-list-of-numbers-in-a-data-file
Scripts for computing the average of a list of numbers in a data file
JackWM
Chris Seymour
15,681,543
64
null
null
so-16136943
Extract the second column from each line of input, where the first column is a number and the second column is a double-quoted string that may contain spaces. The output should be just the quoted string.
{ match($0, /"[^"]*"/); print substr($0, RSTART, RLENGTH) }
1540 "A B" 6 "C" 119 "D"
"A B" "C" "D"
100 "Hello World" 200 "Test" 300 "Foo Bar Baz"
"Hello World" "Test" "Foo Bar Baz"
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/16136943/how-can-i-get-the-second-column-from-command-output
How can I get the second column from command output?
Qiang Xu
catay
16,137,100
276
null
null
so-17001849
Print lines where the third field contains the substring 'snow'.
$3 ~ /snow/ { print }
C1 C2 C3 1 a snow 2 b snowman snow c sowman
1 a snow 2 b snowman
id name description 1 test snowflake 2 demo ice 3 alpha snow
1 test snowflake 3 alpha snow
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/17001849/awk-partly-string-match-if-column-word-partly-matches
awk partly string match (if column/word partly matches)
pogibas
Ahmed Masud
17,001,897
126
null
null
so-17988756
Extract and print lines that appear strictly between lines containing 'abc' and lines containing 'mno', excluding the marker lines themselves. Handle multiple occurrences of these markers throughout the file.
/abc/{flag=1;next}/mno/{flag=0}flag
abc def1 ghi1 jkl1 mno abc def2 ghi2
def1 ghi1 jkl1 def2 ghi2
start abc line A line B mno end abc line C mno
line A line B line C
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/17988756/how-to-select-lines-between-two-marker-patterns-which-may-occur-multiple-times-w
How to select lines between two marker patterns which may occur multiple times with awk/sed
dvai
fedorqui
17,988,834
170
null
null
so-19149731
Calculate and print the average of the values in the second column of the input data. Print the result in the format 'Average: <value>'.
{ sum += $2 } END { if (NR > 0) print "Average: " sum / NR }
Alice 10 Bob 20 Charlie 30
Average: 20
Item1 5.5 Item2 4.5 Item3 10
Average: 6.66667
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/19149731/use-awk-to-find-average-of-a-column
Use awk to find average of a column
Ben Zifkin
imp25
19,150,191
83
null
null
so-20600982
Write an awk program that reads comma-separated values from stdin. For each line containing a comma, remove all leading and trailing whitespace from the second field only, then print the first field, a comma, and the trimmed second field. Lines without commas should be ignored.
BEGIN{FS=","; OFS=","} /,/{gsub(/^[ \t]+/,"",$2); gsub(/[ \t]+$/,"",$2); print $1,$2}
Name, Order Trim, working cat,cat1
Name,Order Trim,working cat,cat1
ID , Value 123 , 456 NoCommaHere
ID ,Value 123 ,456
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/20600982/trim-leading-and-trailing-spaces-from-a-string-in-awk
Trim leading and trailing spaces from a string in awk
Marjer
Floris
20,601,021
78
null
null
so-20752043
Print each line of input prefixed with its zero-based line number followed by a comma. The first line should be numbered 0.
{ print NR-1 "," $0 }
line one line two line three
0,line one 1,line two 2,line three
hello world
0,hello 1,world
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/20752043/print-line-numbers-starting-at-zero-using-awk
Print line numbers starting at zero using awk
user790049
Lance Roberts
20,752,092
87
null
null
so-2096490
Print the second-to-last field of each input line.
{print $(NF-1)}
one two three four alpha beta gamma
three beta
a b c d e f g h
b g
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/2096490/print-second-to-last-column-field-in-awk
Print second-to-last column/field in `awk`
Brian G
Chris Kannon
2,096,526
225
null
null
so-22190902
Print the first field of the first line of the input.
NR==1{print $1; exit}
SUSE Linux Enterprise Server 11 (x86_64) VERSION = 11 PATCHLEVEL = 2
SUSE
Hello World Test Second Line Data Third Line Info
Hello
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/22190902/cut-or-awk-command-to-print-first-field-of-first-row
cut or awk command to print first field of first row
user3331975
devnull
22,190,928
114
null
null
so-2310605
Remove all leading whitespace (spaces and tabs) from each line of the input text.
{ sub(/^[ \t]+/, ""); print }
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
indented line mixed spaces and tabs no indent
indented line mixed spaces and tabs no indent
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/2310605/how-to-remove-leading-whitespace-from-each-line-in-a-file
How to remove leading whitespace from each line in a file
Lazer
shuvalov
2,310,620
83
null
null
so-2626274
Print all columns except the first three, preserving original spacing between the remaining fields.
{ sub(/([^ ]+ +){3}/, ""); print }
1 2 3 4 5 6 7 a b c d e f g h 10 20 30 40
1 2 3 4 5 6 7 a b c d e f g h 10 20 30 40
first second third fourth fifth 1 2 3 4 5 6 x y z w
first second third fourth fifth 1 2 3 4 5 6 x y z w
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/2626274/print-all-but-the-first-three-columns
Print all but the first three columns
hhh
olibre
18,817,331
125
null
null
so-2702564
Calculate and print the sum of all numbers provided in the input, with one number per line.
{ sum += $1 } END { print sum }
34 42 11 6 2 99
194
10 20 30
60
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/2702564/how-can-i-quickly-sum-all-numbers-in-a-file
How can I quickly sum all numbers in a file?
Mark Roberts
brian d foy
2,702,614
275
null
null
so-27028928
Concatenate the first and second fields of each line with a space in between and print the result.
{print $1 " " $2}
hello how are you i am fine thanks
hello how i am
foo bar baz alpha beta gamma
foo bar alpha beta
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/27028928/awk-concatenate-two-string-variable-and-assign-to-a-third
awk - concatenate two string variable and assign to a third
user3738926
fedorqui
27,028,953
108
null
null
so-28905083
Calculate and print the sum of the 57th comma-separated field across all lines in the input.
BEGIN { FS=","; sum=0 } { sum += $57 } END { print sum }
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,10
0
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,5 a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,15
0
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/28905083/how-to-sum-a-column-in-awk
How to Sum a column in AWK?
Ajo
mpromonet
28,905,292
69
null
null
so-2957094
Print all lines where the second whitespace-separated field is exactly the string LINUX.
$2 == "LINUX" { print }
1 LINUX param1 value1 2 LINUXparam2 value2 3 SOLARIS param3 value3 4 SOLARIS param4 value4
1 LINUX param1 value1
10 LINUX test data 20 LINUXX test data 30 WINDOWS test data
10 LINUX test data
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/2957094/how-to-use-awk-to-print-lines-where-a-field-matches-a-specific-string
How to use awk to print lines where a field matches a specific string?
yael
Hank Gay
2,957,225
71
null
null
so-2961635
Write an awk program that removes the first two fields from each input line and prints the remaining content, preserving the original spacing between the remaining fields.
{$1=$2=""; print $0}
! path/to/file.c another/path M src/main.c
another/path
? docs/readme.txt A lib/utils.h extra info here
extra info here
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/2961635/using-awk-to-print-all-columns-from-the-nth-to-the-last
Using awk to print all columns from the nth to the last
Andy
zed_0xff
2,961,994
486
null
null
so-3080693
Print only the last line of the input text.
{ line = $0 } END { print line }
First line Second line Third line
Third line
Alpha Beta Gamma Delta
Delta
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/3080693/print-the-last-line-of-a-file-from-the-cli
Print the last line of a file, from the CLI
yael
Joey
3,080,722
70
null
null
so-38972736
Print all lines from stdin that fall between the pattern 'PAT1' and 'PAT2', inclusive of both patterns. If multiple blocks exist, print all of them.
/PAT1/,/PAT2/
1 2 PAT1 3 - first block 4 PAT2 5 6 PAT1 7 - second block PAT2 8
PAT1 3 - first block 4 PAT2 PAT1 7 - second block PAT2
START PAT1 A B PAT2 END PAT1 C PAT2
PAT1 A B PAT2 PAT1 C PAT2
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/38972736/how-to-print-lines-between-two-patterns-inclusive-or-exclusive-in-sed-awk-or
How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)?
fedorqui
fedorqui
38,972,737
116
null
null
so-4198138
Reorder each line of a space-separated table by moving the first field to the end, preserving the order of the remaining fields.
{first=$1; $1=""; sub(/^ /, ""); print $0, first}
AE United Arab Emirates
United Arab Emirates AE
AG Antigua & Barbuda US United States of America
Antigua & Barbuda AG United States of America US
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/4198138/printing-everything-except-the-first-field-with-awk
Printing everything except the first field with awk
cfischer
Ben Jackson
4,198,169
161
null
null
so-4304917
Print the last two columns of each line.
{ print $(NF-1), $NF }
a b c d e 1 2 3 x y
d e 2 3 x y
one two three four alpha beta gamma col1 col2
three four beta gamma col1 col2
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/4304917/how-to-print-last-two-columns-using-awk
How to print last two columns using awk
vehomzzz
codaddict
4,304,949
126
null
null
so-5081916
Read lines from stdin and print all fields starting from the 9th field to the end of the line, separated by spaces. If there are fewer than 9 fields, print an empty line.
{ s = ""; for (i = 9; i <= NF; i++) s = s (s ? " " : "") $i; print s }
1 2 3 4 5 6 7 8 9 10 11 a b c d e f g h i j k l m n
9 10 11 i j k l m n
one two three four five six seven eight nine ten two four six eight ten twelve fourteen sixteen eighteen twenty
nine ten eighteen twenty
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/5081916/how-to-print-all-the-columns-after-a-particular-number-using-awk
How to print all the columns after a particular number using awk?
Lazer
Amadan
5,082,055
116
null
null
so-5374239
Read tab-separated values from stdin. Replace the third field with the string 'REPLACED' and print the modified line, ensuring fields remain separated by tabs.
BEGIN { FS = "\t"; OFS = "\t" } { $3 = "REPLACED"; print }
LOAD_SETTLED LOAD_INIT 2011-01-13 03:50:01 STATUS_OK STATUS_PENDING 2011-02-14 12:00:00
LOAD_SETTLED LOAD_INIT REPLACED STATUS_OK STATUS_PENDING REPLACED
COL_A COL_B COL_C COL_D VAL_1 VAL_2 VAL_3 VAL_4
COL_A COL_B REPLACED COL_D VAL_1 VAL_2 REPLACED VAL_4
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/5374239/tab-separated-values-in-awk
Tab separated values in awk
shantanuo
glenn jackman
5,376,527
118
null
null
so-5536018
Print only the specific field from each line that exactly matches the string 'yyy'.
{for(i=1;i<=NF;i++){if($i=="yyy"){print $i}}}
xxx yyy zzz aaa bbb ccc yyy ddd eee fff ggg yyy
yyy yyy yyy
hello world foo bar yyy baz qux yyy
yyy yyy
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/5536018/how-to-print-matched-regex-pattern-using-awk
How to print matched regex pattern using awk?
marverix
kurumi
5,536,068
170
null
null
so-6022384
Print the 5th line of the input text.
NR==5{print;exit}
Line one Line two Line three Line four Line five Line six
Line five
Alpha Beta Gamma Delta Epsilon
Epsilon
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/6022384/bash-tool-to-get-nth-line-from-a-file
Bash tool to get nth line from a file
Vlad Vivdovitch
anubhava
6,022,431
914
null
null
so-8009664
Split the input string by the pipe character '|' and print the resulting fields in reverse order, separated by spaces.
{ n = split($0, a, "|"); for (i = n; i >= 1; i--) printf "%s%s", a[i], (i > 1 ? " " : "\n") }
12|23|11
11 23 12
A|B|C|D
D C B A
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/8009664/how-to-split-a-delimited-string-into-an-array-in-awk
How to split a delimited string into an array in awk?
Mohamed Saligh
Calin Paul Alexandru
8,009,724
274
null
null
so-8786634
Read lines from stdin and print the number of characters in each line.
{ print length }
Hello World Short This is a longer sentence.
11 5 26
abc 12345
3 5
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/8786634/how-to-print-the-number-of-characters-in-each-line-of-a-text-file
How to print the number of characters in each line of a text file
vikas368
Fred Foo
8,786,674
116
null
null
so-9351902
Count the number of whitespace-separated fields in each line of the input.
{ print NF }
hello world foo bar baz single
2 3 1
one two three four alpha beta
4 2
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/9351902/how-can-i-get-the-length-of-an-array-in-awk
How can I get the length of an array in awk?
softghost
shellter
9,351,954
79
null
null
so-9591744
Append the string ' anotherthing' to the end of any line that starts with 'all:'. Print all lines, modified or not.
/^all:/ { $0 = $0 " anotherthing" } { print }
somestuff... all: thing otherthing some other stuff
somestuff... all: thing otherthing anotherthing some other stuff
start all: foo bar end
start all: foo bar anotherthing end
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/9591744/how-to-add-to-the-end-of-lines-containing-a-pattern-with-sed-or-awk
How to add to the end of lines containing a pattern with sed or awk?
yasar
user219882
9,591,835
98
null
null
so-9605232
Merge every two consecutive lines of input into a single line, separated by a space.
NR%2{printf "%s ",$0;next;}1
KEY 4048:1736 string 3 KEY 0:1772 string 1
KEY 4048:1736 string 3 KEY 0:1772 string 1
Line A Line B Line C Line D
Line A Line B Line C Line D
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/9605232/how-to-merge-every-two-lines-into-one-from-the-command-line
How to merge every two lines into one from the command line?
shantanuo
Kent
9,605,559
229
null
null
so-22190902-p1
Output the initial field from the very first line of the input.
NR==1{print $1; exit}
SUSE Linux Enterprise Server 11 (x86_64) VERSION = 11 PATCHLEVEL = 2
SUSE
Hello World Test Second Line Data Third Line Info
Hello
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/22190902/cut-or-awk-command-to-print-first-field-of-first-row
cut or awk command to print first field of first row
user3331975
devnull
22,190,928
114
so-22190902
qwen/qwen3.7-plus
so-2310605-p1
Strip leading spaces and tabs from every line in the input text.
{ sub(/^[ \t]+/, ""); print }
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
indented line mixed spaces and tabs no indent
indented line mixed spaces and tabs no indent
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/2310605/how-to-remove-leading-whitespace-from-each-line-in-a-file
How to remove leading whitespace from each line in a file
Lazer
shuvalov
2,310,620
83
so-2310605
qwen/qwen3.7-plus
so-2626274-p1
Display all fields starting from the fourth one, keeping the original whitespace between them intact.
{ sub(/([^ ]+ +){3}/, ""); print }
1 2 3 4 5 6 7 a b c d e f g h 10 20 30 40
1 2 3 4 5 6 7 a b c d e f g h 10 20 30 40
first second third fourth fifth 1 2 3 4 5 6 x y z w
first second third fourth fifth 1 2 3 4 5 6 x y z w
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/2626274/print-all-but-the-first-three-columns
Print all but the first three columns
hhh
olibre
18,817,331
125
so-2626274
qwen/qwen3.7-plus
so-2702564-p1
Compute and output the total sum of all numbers listed in the input, assuming each number is on its own line.
{ sum += $1 } END { print sum }
34 42 11 6 2 99
194
10 20 30
60
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/2702564/how-can-i-quickly-sum-all-numbers-in-a-file
How can I quickly sum all numbers in a file?
Mark Roberts
brian d foy
2,702,614
275
so-2702564
qwen/qwen3.7-plus
so-27028928-p1
Join the first two fields of each line with a single space and print the combined result.
{print $1 " " $2}
hello how are you i am fine thanks
hello how i am
foo bar baz alpha beta gamma
foo bar alpha beta
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/27028928/awk-concatenate-two-string-variable-and-assign-to-a-third
awk - concatenate two string variable and assign to a third
user3738926
fedorqui
27,028,953
108
so-27028928
qwen/qwen3.7-plus
so-28905083-p1
Calculate and print the sum of the 57th comma-separated field across all lines in the input.
BEGIN { FS=","; sum=0 } { sum += $57 } END { print sum }
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,10
0
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,5 a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,15
0
real-stackoverflow
3
train
original-grammar-copy
CC-BY-SA-4.0
https://stackoverflow.com/questions/28905083/how-to-sum-a-column-in-awk
How to Sum a column in AWK?
Ajo
mpromonet
28,905,292
69
so-28905083
qwen/qwen3.7-plus
so-17001849-p1
Output only those lines where the third field includes the substring 'snow'.
$3 ~ /snow/ { print }
C1 C2 C3 1 a snow 2 b snowman snow c sowman
1 a snow 2 b snowman
id name description 1 test snowflake 2 demo ice 3 alpha snow
1 test snowflake 3 alpha snow
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/17001849/awk-partly-string-match-if-column-word-partly-matches
awk partly string match (if column/word partly matches)
pogibas
Ahmed Masud
17,001,897
126
so-17001849
qwen/qwen3.7-plus
so-17988756-p1
Retrieve and display all lines situated strictly between markers containing 'abc' and 'mno', omitting the marker lines themselves, while processing multiple such pairs across the file.
/abc/{flag=1;next}/mno/{flag=0}flag
abc def1 ghi1 jkl1 mno abc def2 ghi2
def1 ghi1 jkl1 def2 ghi2
start abc line A line B mno end abc line C mno
line A line B line C
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/17988756/how-to-select-lines-between-two-marker-patterns-which-may-occur-multiple-times-w
How to select lines between two marker patterns which may occur multiple times with awk/sed
dvai
fedorqui
17,988,834
170
so-17988756
qwen/qwen3.7-plus
so-19149731-p1
Compute the mean of the values in the second column and output it as 'Average: <value>'.
{ sum += $2 } END { if (NR > 0) print "Average: " sum / NR }
Alice 10 Bob 20 Charlie 30
Average: 20
Item1 5.5 Item2 4.5 Item3 10
Average: 6.66667
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/19149731/use-awk-to-find-average-of-a-column
Use awk to find average of a column
Ben Zifkin
imp25
19,150,191
83
so-19149731
qwen/qwen3.7-plus
so-20600982-p1
Create an awk script that processes comma-separated input from stdin: for lines with commas, trim leading and trailing whitespace from the second field only, then print the first field, a comma, and the cleaned second field; skip lines lacking commas.
BEGIN{FS=","; OFS=","} /,/{gsub(/^[ \t]+/,"",$2); gsub(/[ \t]+$/,"",$2); print $1,$2}
Name, Order Trim, working cat,cat1
Name,Order Trim,working cat,cat1
ID , Value 123 , 456 NoCommaHere
ID ,Value 123 ,456
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/20600982/trim-leading-and-trailing-spaces-from-a-string-in-awk
Trim leading and trailing spaces from a string in awk
Marjer
Floris
20,601,021
78
so-20600982
qwen/qwen3.7-plus
so-20752043-p1
Prepend each input line with its zero-indexed line number and a comma, starting the count at 0 for the first line.
{ print NR-1 "," $0 }
line one line two line three
0,line one 1,line two 2,line three
hello world
0,hello 1,world
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/20752043/print-line-numbers-starting-at-zero-using-awk
Print line numbers starting at zero using awk
user790049
Lance Roberts
20,752,092
87
so-20752043
qwen/qwen3.7-plus
so-2096490-p1
Display the penultimate field from every input line.
{print $(NF-1)}
one two three four alpha beta gamma
three beta
a b c d e f g h
b g
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/2096490/print-second-to-last-column-field-in-awk
Print second-to-last column/field in `awk`
Brian G
Chris Kannon
2,096,526
225
so-2096490
qwen/qwen3.7-plus
so-1444406-p1
Deduplicate the input lines, keeping only the first instance of each while maintaining the original sequence.
!seen[$0]++
apple banana apple cherry banana date
apple banana cherry date
line1 line2 line1 line3 line2 line4
line1 line2 line3 line4
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/1444406/how-to-delete-duplicate-lines-in-a-file-without-sorting-it-in-unix
How to delete duplicate lines in a file without sorting it in Unix
Vijay
Jonas Elfstr&#246;m
1,444,448
214
so-1444406
qwen/qwen3.7-plus
so-14462529-p1
For every line in the input, output only its initial 22 characters.
{ print substr($0, 1, 22) }
000000000001199998000180000 DUMMY RAG # MFR NOT ST 1999980 ZZ- 0 0 0ZZ- 000000000002199998000180000 DUMMY RAG # MFR NOT ST 1999980 ZZ- 0 0 0ZZ-
0000000000011999980001 0000000000021999980001
ABCDEFGHIJKL1234567890EXTRA Short
ABCDEFGHIJKL1234567890 Short
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/14462529/how-to-get-first-n-characters-of-each-line-in-unix-data-file
How to get first n characters of each line in unix data file
Teja
Chris Seymour
14,462,614
82
so-14462529
qwen/qwen3.7-plus
so-14739057-p1
Output the third field for any line where the eighth field matches "ClNonZ" exactly.
$8 == "ClNonZ" { print $3 }
2 14 0.180467091 0.800424628 0 0.0566 0.0103 ClNonZ 5 22 0.010615711 0.959660297 0.010615711 0.0476 0.0061 ClNonZ 9 31 0.492569002 0.350318471 0.138004246 0.0485 0.0088 ClNonZ
0.180467091 0.010615711 0.492569002
1 11 0.959660297 0 0.021231423 -0.0073 -0.0031 MhZisp 3 19 0.98089172 0 0 -0.0158 0.0124 MhNonZ 2 14 0.180467091 0.800424628 0 0.0566 0.0103 ClNonZ
0.180467091
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/14739057/using-awk-with-column-value-conditions
using awk with column value conditions
user1687130
Rob Davis
14,739,101
137
so-14739057
qwen/qwen3.7-plus
so-1506521-p1
Display the third field from line 5 of the input.
NR==5{print $3; exit}
Line1 F1 F2 F3 F4 Line2 F1 F2 F3 F4 Line3 F1 F2 F3 F4 Line4 F1 F2 F3 F4 Line5 F1 F2 TargetValue F4
F2
A B C D E 1 2 3 4 5 a b c d e x y z w v p q r s t
r
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/1506521/select-row-and-element-in-awk
Select row and element in awk
Tim
Dennis Williamson
1,506,601
108
so-1506521
qwen/qwen3.7-plus
so-15681498-p1
Compute the mean of all whitespace-delimited numbers in the input and print it as 'ave: <value>' using standard float precision.
{s+=$1} END{if(NR>0) print "ave:", s/NR}
1.00 1.23 54.4 213.2 3.4
ave: 1
10 20 30
ave: 10
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/15681498/scripts-for-computing-the-average-of-a-list-of-numbers-in-a-data-file
Scripts for computing the average of a list of numbers in a data file
JackWM
Chris Seymour
15,681,543
64
so-15681498
qwen/qwen3.7-plus
so-16136943-p1
Extract the second column from each line of input, where the first column is a number and the second column is a double-quoted string that may contain spaces. The output should be just the quoted string.
{ match($0, /"[^"]*"/); print substr($0, RSTART, RLENGTH) }
1540 "A B" 6 "C" 119 "D"
"A B" "C" "D"
100 "Hello World" 200 "Test" 300 "Foo Bar Baz"
"Hello World" "Test" "Foo Bar Baz"
real-stackoverflow
3
train
original-grammar-copy
CC-BY-SA-4.0
https://stackoverflow.com/questions/16136943/how-can-i-get-the-second-column-from-command-output
How can I get the second column from command output?
Qiang Xu
catay
16,137,100
276
so-16136943
qwen/qwen3.7-plus
so-1068650-p1
Create an awk script that strips the UTF-8 Byte Order Mark (bytes EF BB BF) from the start of the first input line if present, and then prints every line.
NR==1{sub(/^\xef\xbb\xbf/,"")}1
Hello World Second Line Third Line
Hello World Second Line Third Line
No BOM Here Another Line
No BOM Here Another Line
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/1068650/using-awk-to-remove-the-byte-order-mark
Using awk to remove the Byte-order mark
Boldewyn
Bartosz
1,068,700
107
so-1068650
qwen/qwen3.7-plus
so-11952854-p1
Develop an awk program that processes stdin by splitting each line into whitespace-delimited fields. For any field containing an '@', separate it into a key and value; if the value is empty or only spaces, set it to 'Y'. Output each resulting pair as 'key=value' on its own line, maintaining the original input order.
{ for (i = 1; i <= NF; i++) { if (index($i, "@") > 0) { n = split($i, parts, "@") key = parts[1] val = "" for (j = 2; j <= n; j++) { if (j > 2) val = val "@" val = val parts[j] } if (val ~ /^[[:space:]]*$/) { val = "Y" } print key "=" val ...
user@john admin@ host@server1 config@ data@value
user=john admin=Y host=server1 config=Y data=value
a@ b@ c@d e@f
a=Y b=Y c=d e=f
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/11952854/how-to-check-if-the-variable-value-in-awk-script-is-null-or-empty
How to check if the variable value in AWK script is null or empty?
samarth
Levon
11,952,924
64
so-11952854
qwen/qwen3.7-plus
so-11967776-p1
Exchange the positions of the first and second whitespace-separated fields in each input line while keeping the remainder of the line intact.
{ temp = $1; $1 = $2; $2 = temp; print }
Affy-id chr 0 pos NA06984 Col1 Col2 Rest of line
chr Affy-id 0 pos NA06984 Col2 Col1 Rest of line
A B C D E First Second Third
B A C D E Second First Third
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/11967776/swap-two-columns-awk-sed-python-perl
Swap two columns - awk, sed, python, perl
Charley Farley
perreal
11,967,849
83
so-11967776
qwen/qwen3.7-plus
so-12204192-p1
Extract the third path component, the fifth path component, and the value after the equals sign from each line. Use forward slashes and equals signs as delimiters.
BEGIN { FS = "[/=]" } { print $3, $5, $8 }
/logs/tc0001/tomcat/tomcat7.1/conf/catalina.properties:app.env.server.name = demo.example.com /logs/tc0001/tomcat/tomcat7.2/conf/catalina.properties:app.env.server.name = quest.example.com
tc0001 tomcat7.1 demo.example.com tc0001 tomcat7.2 quest.example.com
/data/projA/src/main/java/App.java:version = 1.0.0 /data/projB/lib/utils/helper.py:mode = production
projA main 1.0.0 projB utils
real-stackoverflow
3
train
original-grammar-copy
CC-BY-SA-4.0
https://stackoverflow.com/questions/12204192/using-multiple-delimiters-in-awk
Using multiple delimiters in awk
Satish
embedded.kyle
12,204,350
306
so-12204192
qwen/qwen3.7-plus
so-12297859-p1
Write an awk utility that reads from stdin and outputs only the portion of each line following the final colon; if no colon exists, output the whole line.
{idx=match($0, /:[^:]*$/); if(idx>0) print substr($0, idx+1); else print $0}
TF_list_to_test10004/Nus_k0.345_t0.1_e0.1.adj:PKMYT1 path/to/file:GENE_A no_colon_here
PKMYT1 GENE_A no_colon_here
server:port:service_name simple_line key:value
service_name simple_line value
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/12297859/remove-all-text-before-colon
Remove all text before colon
NewUsr_stat
Sacha Epskamp
12,297,934
77
so-12297859
qwen/qwen3.7-plus
so-13046167-p1
Output the final field for every input line that includes the substring 'A1'.
/A1/ {print $NF}
A1 123 456 B1 234 567 C1 345 678 A1 098 766 B1 987 6545 C1 876 5434
456 766
A1 foo bar X1 ignore this A1 baz qux Y1 skip me
bar qux
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/13046167/printing-the-last-column-of-a-line-in-a-file
Printing the last column of a line in a file
Rayne
Olaf Dietsche
13,046,224
201
so-13046167
qwen/qwen3.7-plus
so-2957094-p1
Output every line whose second whitespace-delimited field matches the exact string LINUX.
$2 == "LINUX" { print }
1 LINUX param1 value1 2 LINUXparam2 value2 3 SOLARIS param3 value3 4 SOLARIS param4 value4
1 LINUX param1 value1
10 LINUX test data 20 LINUXX test data 30 WINDOWS test data
10 LINUX test data
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/2957094/how-to-use-awk-to-print-lines-where-a-field-matches-a-specific-string
How to use awk to print lines where a field matches a specific string?
yael
Hank Gay
2,957,225
71
so-2957094
qwen/qwen3.7-plus
so-2961635-p1
Create an awk script that strips the first two fields from each line and outputs the rest, maintaining the original spacing between the remaining fields.
{$1=$2=""; print $0}
! path/to/file.c another/path M src/main.c
another/path
? docs/readme.txt A lib/utils.h extra info here
extra info here
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/2961635/using-awk-to-print-all-columns-from-the-nth-to-the-last
Using awk to print all columns from the nth to the last
Andy
zed_0xff
2,961,994
486
so-2961635
qwen/qwen3.7-plus
so-3080693-p1
Display only the final line of the input text.
{ line = $0 } END { print line }
First line Second line Third line
Third line
Alpha Beta Gamma Delta
Delta
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/3080693/print-the-last-line-of-a-file-from-the-cli
Print the last line of a file, from the CLI
yael
Joey
3,080,722
70
so-3080693
qwen/qwen3.7-plus
so-38972736-p1
Extract and print all lines from stdin located between the patterns 'PAT1' and 'PAT2', including the lines containing these patterns, for every occurrence in the input.
/PAT1/,/PAT2/
1 2 PAT1 3 - first block 4 PAT2 5 6 PAT1 7 - second block PAT2 8
PAT1 3 - first block 4 PAT2 PAT1 7 - second block PAT2
START PAT1 A B PAT2 END PAT1 C PAT2
PAT1 A B PAT2 PAT1 C PAT2
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/38972736/how-to-print-lines-between-two-patterns-inclusive-or-exclusive-in-sed-awk-or
How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)?
fedorqui
fedorqui
38,972,737
116
so-38972736
qwen/qwen3.7-plus
so-4198138-p1
Reorder each line of a space-separated table by moving the first field to the end, preserving the order of the remaining fields.
{first=$1; $1=""; sub(/^ /, ""); print $0, first}
AE United Arab Emirates
United Arab Emirates AE
AG Antigua & Barbuda US United States of America
Antigua & Barbuda AG United States of America US
real-stackoverflow
3
train
original-grammar-copy
CC-BY-SA-4.0
https://stackoverflow.com/questions/4198138/printing-everything-except-the-first-field-with-awk
Printing everything except the first field with awk
cfischer
Ben Jackson
4,198,169
161
so-4198138
qwen/qwen3.7-plus
so-4304917-p1
Output the last two columns for every line.
{ print $(NF-1), $NF }
a b c d e 1 2 3 x y
d e 2 3 x y
one two three four alpha beta gamma col1 col2
three four beta gamma col1 col2
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/4304917/how-to-print-last-two-columns-using-awk
How to print last two columns using awk
vehomzzz
codaddict
4,304,949
126
so-4304917
qwen/qwen3.7-plus
so-9351902-p1
For every line in the input, determine and output the count of fields delimited by whitespace.
{ print NF }
hello world foo bar baz single
2 3 1
one two three four alpha beta
4 2
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/9351902/how-can-i-get-the-length-of-an-array-in-awk
How can I get the length of an array in awk?
softghost
shellter
9,351,954
79
so-9351902
qwen/qwen3.7-plus
so-9591744-p1
Output all lines from the input; if a line begins with 'all:', append ' anotherthing' to its end before printing.
/^all:/ { $0 = $0 " anotherthing" } { print }
somestuff... all: thing otherthing some other stuff
somestuff... all: thing otherthing anotherthing some other stuff
start all: foo bar end
start all: foo bar anotherthing end
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/9591744/how-to-add-to-the-end-of-lines-containing-a-pattern-with-sed-or-awk
How to add to the end of lines containing a pattern with sed or awk?
yasar
user219882
9,591,835
98
so-9591744
qwen/qwen3.7-plus
so-9605232-p1
Combine each pair of adjacent input lines into one line, using a space as the separator.
NR%2{printf "%s ",$0;next;}1
KEY 4048:1736 string 3 KEY 0:1772 string 1
KEY 4048:1736 string 3 KEY 0:1772 string 1
Line A Line B Line C Line D
Line A Line B Line C Line D
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/9605232/how-to-merge-every-two-lines-into-one-from-the-command-line
How to merge every two lines into one from the command line?
shantanuo
Kent
9,605,559
229
so-9605232
qwen/qwen3.7-plus
so-5081916-p1
Read lines from stdin and print all fields starting from the 9th field to the end of the line, separated by spaces. If there are fewer than 9 fields, print an empty line.
{ s = ""; for (i = 9; i <= NF; i++) s = s (s ? " " : "") $i; print s }
1 2 3 4 5 6 7 8 9 10 11 a b c d e f g h i j k l m n
9 10 11 i j k l m n
one two three four five six seven eight nine ten two four six eight ten twelve fourteen sixteen eighteen twenty
nine ten eighteen twenty
real-stackoverflow
3
train
original-grammar-copy
CC-BY-SA-4.0
https://stackoverflow.com/questions/5081916/how-to-print-all-the-columns-after-a-particular-number-using-awk
How to print all the columns after a particular number using awk?
Lazer
Amadan
5,082,055
116
so-5081916
qwen/qwen3.7-plus
so-5374239-p1
Read tab-separated values from stdin. Replace the third field with the string 'REPLACED' and print the modified line, ensuring fields remain separated by tabs.
BEGIN { FS = "\t"; OFS = "\t" } { $3 = "REPLACED"; print }
LOAD_SETTLED LOAD_INIT 2011-01-13 03:50:01 STATUS_OK STATUS_PENDING 2011-02-14 12:00:00
LOAD_SETTLED LOAD_INIT REPLACED STATUS_OK STATUS_PENDING REPLACED
COL_A COL_B COL_C COL_D VAL_1 VAL_2 VAL_3 VAL_4
COL_A COL_B REPLACED COL_D VAL_1 VAL_2 REPLACED VAL_4
real-stackoverflow
3
train
original-grammar-copy
CC-BY-SA-4.0
https://stackoverflow.com/questions/5374239/tab-separated-values-in-awk
Tab separated values in awk
shantanuo
glenn jackman
5,376,527
118
so-5374239
qwen/qwen3.7-plus
so-5536018-p1
For every input line, identify and print the specific field that is an exact match for the string 'yyy'.
{for(i=1;i<=NF;i++){if($i=="yyy"){print $i}}}
xxx yyy zzz aaa bbb ccc yyy ddd eee fff ggg yyy
yyy yyy yyy
hello world foo bar yyy baz qux yyy
yyy yyy
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/5536018/how-to-print-matched-regex-pattern-using-awk
How to print matched regex pattern using awk?
marverix
kurumi
5,536,068
170
so-5536018
qwen/qwen3.7-plus
so-6022384-p1
Output the fifth line from the provided input text.
NR==5{print;exit}
Line one Line two Line three Line four Line five Line six
Line five
Alpha Beta Gamma Delta Epsilon
Epsilon
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/6022384/bash-tool-to-get-nth-line-from-a-file
Bash tool to get nth line from a file
Vlad Vivdovitch
anubhava
6,022,431
914
so-6022384
qwen/qwen3.7-plus
so-8009664-p1
Divide the input string using '|' as the delimiter and display the resulting segments in reverse order, joined by spaces.
{ n = split($0, a, "|"); for (i = n; i >= 1; i--) printf "%s%s", a[i], (i > 1 ? " " : "\n") }
12|23|11
11 23 12
A|B|C|D
D C B A
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/8009664/how-to-split-a-delimited-string-into-an-array-in-awk
How to split a delimited string into an array in awk?
Mohamed Saligh
Calin Paul Alexandru
8,009,724
274
so-8009664
qwen/qwen3.7-plus
so-8786634-p1
Read each line from stdin and output its character count.
{ print length }
Hello World Short This is a longer sentence.
11 5 26
abc 12345
3 5
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/8786634/how-to-print-the-number-of-characters-in-each-line-of-a-text-file
How to print the number of characters in each line of a text file
vikas368
Fred Foo
8,786,674
116
so-8786634
qwen/qwen3.7-plus
so-10693608
Write an awk program that reads tab-separated input and removes the second and third fields from each line. The output should use tabs as separators and must not contain empty fields or extra delimiters where the removed fields were.
BEGIN { FS="\t"; OFS="\t" } { for (i=4; i<=NF; i++) $(i-2)=$i; NF-=2; print }
one two three four five test red green blue yellow
one four five test blue yellow
a b c d 1 2 3 4 5 6
a d 1 4 5 6
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/10693608/is-there-a-way-to-completely-delete-fields-in-awk-so-that-extra-delimiters-do-n
Is there a way to completely delete fields in awk, so that extra delimiters do not print?
merlin2011
ghoti
38,311,342
23
null
null
so-12714155
Calculate the average of the numbers in the first column of the input and print it in fixed-point notation with 7 decimal places, prefixed by 'Avg monitoring time = '.
{sum+=$1; ++n} END {avg=sum/n; printf "Avg monitoring time = %.7f\n",avg}
0.00001 0.00002 0.00003
Avg monitoring time = 0.0000200
1.5e-05 1.5e-05
Avg monitoring time = 0.0000150
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/12714155/how-can-i-make-awk-not-use-scientific-notation-when-printing-small-values
How can I make awk not use scientific notation when printing small values?
Manuel Selva
C2H5OH
12,714,193
53
null
null
so-21309020
Print only the even-numbered lines from the input text.
NR % 2 == 0
Line 1 Line 2 Line 3 Line 4
Line 2 Line 4
Alpha Beta Gamma Delta Epsilon
Beta Delta
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/21309020/remove-odd-or-even-lines-from-a-text-file
Remove odd or even lines from a text file
SamuelNLP
Thor
21,309,073
53
null
null
so-2924251
Read a list of file paths from standard input, one per line. Prepend a sequential line number starting from 1 to each line, separated by a space.
{ print NR, $0 }
/home/user/docs/report.pdf /home/user/docs/image.png /home/user/data.csv
1 /home/user/docs/report.pdf 2 /home/user/docs/image.png 3 /home/user/data.csv
/var/log/syslog /var/log/auth.log
1 /var/log/syslog 2 /var/log/auth.log
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/2924251/how-to-number-the-ls-output-in-unix
How to number the ls output in unix?
Snehal
Matthew Slattery
2,924,284
6
null
null
so-56927772
Write an awk program that processes WebVTT subtitle text from stdin. It should remove all lines containing timestamp arrows ('-->'), lines containing HTML-like tags (starting with '<' or containing '</'), lines containing square brackets ('['), and duplicate consecutive lines. Print only the unique plain text dialogue ...
/-->/ { next } /\[.*\]/ { next } /<[^>]*>/ { next } { gsub(/<[^>]*>/, ""); if ($0 != prev) { print; prev = $0 } }
WEBVTT 00:00:05.200 --> 00:00:05.210 align:start position:0% [Applause] hi<00:00:06.440><c> I'm</c><00:00:07.440><c> here</c> hi I'm here 00:00:11.860 --> 00:00:11.870 align:start position:0% hi I'm here
WEBVTT hi I'm here
00:00:01.000 --> 00:00:02.000 Hello World 00:00:03.000 --> 00:00:04.000 <b>Bold Text</b> Hello World Goodbye
Hello World Goodbye
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/56927772/convert-webvtt-file-from-youtube-to-plain-text
Convert WebVTT file from Youtube to plain text
user1029296
l&#39;L&#39;l
56,927,959
8
null
null
so-5917576
Read lines from standard input and output them sorted by their total character length (including spaces) in ascending order. If multiple lines have the same length, preserve their original relative order from the input.
{ lines[NR] = $0 lens[NR] = length($0) } END { for (i = 1; i <= NR; i++) { for (j = i + 1; j <= NR; j++) { if (lens[j] < lens[i]) { tmp = lines[i]; lines[i] = lines[j]; lines[j] = tmp tmp = lens[i]; lens[i] = lens[j]; lens[j] = tmp } } } for (i = 1; i <= NR; i++) { prin...
AS2345,ASDF1232, Mr. Plain Example, 110 Binary ave.,Atlantis,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mrs. Plain Example, 1121110 Ternary st. 110 Binary ave..,Atlantis,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mr. Plain Example, 110 Binary ave.,Liberty City,RI,12345,(999)12...
AS2345,ASDF1232, Mr. Plain Example, 110 Binary ave.,Atlantis,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mr. Plain Example, 110 Ternary ave.,Some City,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mr. Plain Example, 110 Binary ave.,Liberty City,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mrs. Plain Example, 1121110 Te...
aa A line with MORE spaces bb The very longest line in the file ccb 9 dd equal len. Orig pos = 1 500 dd equal len. Orig pos = 2 ccz cca ee A line with some spaces 1 dd equal len. Orig pos = 3 ff 5 dd equal len. Orig pos = 4 g
g ff cca ccb ccz 1 dd equal len. Orig pos = 3 9 dd equal len. Orig pos = 1 5 dd equal len. Orig pos = 4 500 dd equal len. Orig pos = 2 ee A line with some spaces aa A line with MORE spaces bb The very longest line in the file
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/5917576/sort-a-text-file-by-line-length-including-spaces
Sort a text file by line length including spaces
gnarbarian
neillb
5,917,762
221
null
null
so-7359527
Remove all leading and trailing empty lines from the input text, preserving internal empty lines.
{ lines[NR] = $0 } END { start = 1 while (start <= NR && lines[start] == "") start++ end = NR while (end >= start && lines[end] == "") end-- for (i = start; i <= end; i++) { print lines[i] } }
Line 1 Line 2
Line 1 Line 2
Line 1 Line 2
Line 1 Line 2
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/7359527/removing-trailing-starting-newlines-with-sed-awk-tr-and-friends
Removing trailing / starting newlines with sed, awk, tr, and friends
ELLIOTTCABLE
dogbane
7,359,879
56
null
null
so-79642956
Read text from standard input. Replace the first three lines with exactly these three lines: 'line1 data', 'line2 data', and 'line3 data'. Output the new first three lines followed by all remaining lines from the original input starting from line 4.
NR == 1 { print "line1 data" print "line2 data" print "line3 data" } NR > 3 { print }
old line 1 old line 2 old line 3 old line 4 old line 5
line1 data line2 data line3 data old line 4 old line 5
header one header two header three content A content B content C
line1 data line2 data line3 data content A content B content C
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/79642956/sed-delete-and-replace-on-top-of-file-is-not-working-as-expected
sed delete and replace on top of file is not working as expected
Rajeev
Ed Morton
79,642,983
6
null
null
so-79833920
Read tab-separated lines from stdin. For each line, if the second field is a positive number, print the line repeatedly, subtracting 100 from the second field after each print, until the second field becomes zero or negative. Do not print the line if the initial second field is zero or negative.
BEGIN{FS=OFS="\t"} {while($2>0){print; $2-=100}}
chr1 4535 p chr1 5527 q
chr1 4535 p chr1 4435 p chr1 4335 p chr1 4235 p chr1 4135 p chr1 4035 p chr1 3935 p chr1 3835 p chr1 3735 p chr1 3635 p chr1 3535 p chr1 3435 p chr1 3335 p chr1 3235 p chr1 3135 p chr1 3035 p chr1 2935 p chr1 2835 p chr1 2735 p chr1 2635 p chr1 2535 p chr1 2435 p chr1 2335 p chr1 2235 p chr1 2135 p chr1 2035 p chr1 193...
itemA 250 X itemB 99 Y
itemA 250 X itemA 150 X itemA 50 X itemB 99 Y
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/79833920/awk-command-to-subtract-constant-from-a-column-and-print-results
awk command to subtract constant from a column and print results
Matteo
pmf
79,833,924
6
null
null
so-79980449
Process the input stream to keep only the last line of any consecutive sequence of lines starting with '2026-', while printing all other lines immediately. If the file ends with a sequence of such lines, print only the last one.
BEGIN { dateline="" } /^2026-/ { dateline=$0 } ! /^2026-/ { if (dateline) { print dateline } ; print $0 ; dateline="" } END { if (dateline) { print dateline } }
important information 1 2026-07-10T11:12:31.013620-04:00 2026-07-10T11:13:34.058824-04:00 important information 2
important information 1 2026-07-10T11:13:34.058824-04:00 important information 2
2026-07-10T11:15:40.152816-04:00 2026-07-10T11:16:43.190958-04:00 2026-07-10T11:30:22.788192-04:00
2026-07-10T11:30:22.788192-04:00
real-stackoverflow
3
train
stackoverflow-accepted-answer
CC-BY-SA-4.0
https://stackoverflow.com/questions/79980449/remove-multiple-occurrences-of-similar-lines-except-the-last
Remove multiple occurrences of similar lines except the last
blindwillie31
Bill Karwin
79,980,454
9
null
null
so-5917576-p1
Sort input lines by total character count (including spaces) in ascending order, maintaining the original relative order for lines of equal length.
{ lines[NR] = $0 lens[NR] = length($0) } END { for (i = 1; i <= NR; i++) { for (j = i + 1; j <= NR; j++) { if (lens[j] < lens[i]) { tmp = lines[i]; lines[i] = lines[j]; lines[j] = tmp tmp = lens[i]; lens[i] = lens[j]; lens[j] = tmp } } } for (i = 1; i <= NR; i++) { prin...
AS2345,ASDF1232, Mr. Plain Example, 110 Binary ave.,Atlantis,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mrs. Plain Example, 1121110 Ternary st. 110 Binary ave..,Atlantis,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mr. Plain Example, 110 Binary ave.,Liberty City,RI,12345,(999)12...
AS2345,ASDF1232, Mr. Plain Example, 110 Binary ave.,Atlantis,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mr. Plain Example, 110 Ternary ave.,Some City,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mr. Plain Example, 110 Binary ave.,Liberty City,RI,12345,(999)123-5555,1.56 AS2345,ASDF1232, Mrs. Plain Example, 1121110 Te...
aa A line with MORE spaces bb The very longest line in the file ccb 9 dd equal len. Orig pos = 1 500 dd equal len. Orig pos = 2 ccz cca ee A line with some spaces 1 dd equal len. Orig pos = 3 ff 5 dd equal len. Orig pos = 4 g
g ff cca ccb ccz 1 dd equal len. Orig pos = 3 9 dd equal len. Orig pos = 1 5 dd equal len. Orig pos = 4 500 dd equal len. Orig pos = 2 ee A line with some spaces aa A line with MORE spaces bb The very longest line in the file
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/5917576/sort-a-text-file-by-line-length-including-spaces
Sort a text file by line length including spaces
gnarbarian
neillb
5,917,762
221
so-5917576
qwen/qwen3.7-plus
so-7359527-p1
Strip all leading and trailing blank lines from the text while keeping any empty lines that appear within the content.
{ lines[NR] = $0 } END { start = 1 while (start <= NR && lines[start] == "") start++ end = NR while (end >= start && lines[end] == "") end-- for (i = start; i <= end; i++) { print lines[i] } }
Line 1 Line 2
Line 1 Line 2
Line 1 Line 2
Line 1 Line 2
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/7359527/removing-trailing-starting-newlines-with-sed-awk-tr-and-friends
Removing trailing / starting newlines with sed, awk, tr, and friends
ELLIOTTCABLE
dogbane
7,359,879
56
so-7359527
qwen/qwen3.7-plus
so-79642956-p1
Replace the first three lines of the standard input with 'line1 data', 'line2 data', and 'line3 data', then append the rest of the original input starting from line 4.
NR == 1 { print "line1 data" print "line2 data" print "line3 data" } NR > 3 { print }
old line 1 old line 2 old line 3 old line 4 old line 5
line1 data line2 data line3 data old line 4 old line 5
header one header two header three content A content B content C
line1 data line2 data line3 data content A content B content C
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/79642956/sed-delete-and-replace-on-top-of-file-is-not-working-as-expected
sed delete and replace on top of file is not working as expected
Rajeev
Ed Morton
79,642,983
6
so-79642956
qwen/qwen3.7-plus
so-79833920-p1
For each tab-separated line, if the second field is positive, output the line repeatedly while decrementing that field by 100 until it reaches zero or below; skip lines where the initial second field is non-positive.
BEGIN{FS=OFS="\t"} {while($2>0){print; $2-=100}}
chr1 4535 p chr1 5527 q
chr1 4535 p chr1 4435 p chr1 4335 p chr1 4235 p chr1 4135 p chr1 4035 p chr1 3935 p chr1 3835 p chr1 3735 p chr1 3635 p chr1 3535 p chr1 3435 p chr1 3335 p chr1 3235 p chr1 3135 p chr1 3035 p chr1 2935 p chr1 2835 p chr1 2735 p chr1 2635 p chr1 2535 p chr1 2435 p chr1 2335 p chr1 2235 p chr1 2135 p chr1 2035 p chr1 193...
itemA 250 X itemB 99 Y
itemA 250 X itemA 150 X itemA 50 X itemB 99 Y
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/79833920/awk-command-to-subtract-constant-from-a-column-and-print-results
awk command to subtract constant from a column and print results
Matteo
pmf
79,833,924
6
so-79833920
qwen/qwen3.7-plus
so-79980449-p1
Output all lines immediately except for consecutive sequences starting with '2026-', for which only the final line should be printed.
BEGIN { dateline="" } /^2026-/ { dateline=$0 } ! /^2026-/ { if (dateline) { print dateline } ; print $0 ; dateline="" } END { if (dateline) { print dateline } }
important information 1 2026-07-10T11:12:31.013620-04:00 2026-07-10T11:13:34.058824-04:00 important information 2
important information 1 2026-07-10T11:13:34.058824-04:00 important information 2
2026-07-10T11:15:40.152816-04:00 2026-07-10T11:16:43.190958-04:00 2026-07-10T11:30:22.788192-04:00
2026-07-10T11:30:22.788192-04:00
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/79980449/remove-multiple-occurrences-of-similar-lines-except-the-last
Remove multiple occurrences of similar lines except the last
blindwillie31
Bill Karwin
79,980,454
9
so-79980449
qwen/qwen3.7-plus
so-10693608-p1
Write an awk program that reads tab-separated input and removes the second and third fields from each line. The output should use tabs as separators and must not contain empty fields or extra delimiters where the removed fields were.
BEGIN { FS="\t"; OFS="\t" } { for (i=4; i<=NF; i++) $(i-2)=$i; NF-=2; print }
one two three four five test red green blue yellow
one four five test blue yellow
a b c d 1 2 3 4 5 6
a d 1 4 5 6
real-stackoverflow
3
train
original-grammar-copy
CC-BY-SA-4.0
https://stackoverflow.com/questions/10693608/is-there-a-way-to-completely-delete-fields-in-awk-so-that-extra-delimiters-do-n
Is there a way to completely delete fields in awk, so that extra delimiters do not print?
merlin2011
ghoti
38,311,342
23
so-10693608
qwen/qwen3.7-plus
so-12714155-p1
Compute the mean of the values found in column 1 and display the result with exactly 7 decimal places in fixed-point format, preceded by the label 'Avg monitoring time = '.
{sum+=$1; ++n} END {avg=sum/n; printf "Avg monitoring time = %.7f\n",avg}
0.00001 0.00002 0.00003
Avg monitoring time = 0.0000200
1.5e-05 1.5e-05
Avg monitoring time = 0.0000150
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/12714155/how-can-i-make-awk-not-use-scientific-notation-when-printing-small-values
How can I make awk not use scientific notation when printing small values?
Manuel Selva
C2H5OH
12,714,193
53
so-12714155
qwen/qwen3.7-plus
so-21309020-p1
Output only those lines from the input stream that correspond to even line numbers.
NR % 2 == 0
Line 1 Line 2 Line 3 Line 4
Line 2 Line 4
Alpha Beta Gamma Delta Epsilon
Beta Delta
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/21309020/remove-odd-or-even-lines-from-a-text-file
Remove odd or even lines from a text file
SamuelNLP
Thor
21,309,073
53
so-21309020
qwen/qwen3.7-plus
so-2924251-p1
Ingest file paths from stdin (one per line) and prefix each entry with its sequential line number starting at 1, using a space as the delimiter between the number and the path.
{ print NR, $0 }
/home/user/docs/report.pdf /home/user/docs/image.png /home/user/data.csv
1 /home/user/docs/report.pdf 2 /home/user/docs/image.png 3 /home/user/data.csv
/var/log/syslog /var/log/auth.log
1 /var/log/syslog 2 /var/log/auth.log
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/2924251/how-to-number-the-ls-output-in-unix
How to number the ls output in unix?
Snehal
Matthew Slattery
2,924,284
6
so-2924251
qwen/qwen3.7-plus
so-56927772-p1
Develop an awk program to filter WebVTT subtitles from stdin by discarding lines with timestamp arrows ('-->'), HTML-style tags (starting with '<' or containing '</'), square brackets ('['), and consecutive duplicates, leaving only unique plain-text dialogue lines.
/-->/ { next } /\[.*\]/ { next } /<[^>]*>/ { next } { gsub(/<[^>]*>/, ""); if ($0 != prev) { print; prev = $0 } }
WEBVTT 00:00:05.200 --> 00:00:05.210 align:start position:0% [Applause] hi<00:00:06.440><c> I'm</c><00:00:07.440><c> here</c> hi I'm here 00:00:11.860 --> 00:00:11.870 align:start position:0% hi I'm here
WEBVTT hi I'm here
00:00:01.000 --> 00:00:02.000 Hello World 00:00:03.000 --> 00:00:04.000 <b>Bold Text</b> Hello World Goodbye
Hello World Goodbye
real-stackoverflow
3
train
openrouter-paraphrase
CC-BY-SA-4.0
https://stackoverflow.com/questions/56927772/convert-webvtt-file-from-youtube-to-plain-text
Convert WebVTT file from Youtube to plain text
user1029296
l&#39;L&#39;l
56,927,959
8
so-56927772
qwen/qwen3.7-plus

Awkweave Real Questions

A small set of natural-language-to-awk tasks derived from highly voted Stack Overflow questions and accepted answers, used to reduce synthetic-phrasing bias in Awkweave.

Contents

  • 49 reviewed original tasks with unique source questions.
  • 42 accepted paraphrases and 7 guarded original-wording copies.
  • 98 rows total, all with two different input texts and actual outputs from both.

Every program was executed on both inputs with mawk 1.3.4 20200120: 196 successful executions, 0 errors. One unsuitable process-killing conversion was manually excluded. Programs are bare awk, read a single stream on stdin, and avoid files, pipelines, subprocesses, and output redirection.

Source and attribution

Each row includes question_url, question_title, question_owner, answer_owner, and answer_id. These fields identify the original authors and sources. ATTRIBUTION.md lists all source questions. request is a self-contained instruction derived from the question and accepted answer; program is an executable solution.

from datasets import load_dataset

ds = load_dataset("asterbraid/awkweave-so-data", split="train")
print(ds[0])

Limitations

This is a small, high-vote sample, not a representative sample of all awk use. Execution verifies that reference programs run and produce the stored outputs; request-to-program intent was also reviewed. The data is not a new benchmark and was not included in the Awkweave frozen evaluation.

License

Original Stack Overflow content and these derived rows are CC BY-SA 4.0. See SO_DATASET_LICENSE.txt and ATTRIBUTION.md. Included conversion code is Apache-2.0.

Downloads last month
47

Collection including asterbraid/awkweave-so-data