Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Favorites infavorites:mine
infavorites:1234
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with Search options user 148009

A pattern-directed scanning and processing language.

2
votes
Enjoy awk solution: awk -F, '{ diff=$2-$3; if(a[$1]>diff || !a[$1]) { a[$1]=diff; b[$1]=$2 FS $3 } } END{ for(i in a) print i,b[i] }' OFS=',' yourfile The output: c1,5,3 c2,8,4 …
answered Jul 10 '17 by RomanPerekhrest
0
votes
Short sed approach: sed -En 's/^(.{2}).{17}(\S+).*/\1, \2/gp' test.dat The output: 50, Mike 50, Roy
answered May 10 '17 by RomanPerekhrest
9
votes
With awk system() function: Sample input.txt: a b c awk '{ printf "name"; system("tr -dc \047[:alnum:]\047 </dev/urandom | head -c6"); printf "-%s\n", $0 … }' input.txt Sample output: nameSDbQ7T-a nameAliHY0-b nameDUGP2S-c system(command) Execute the operating system command command and then return to the awk program https://www.gnu.org/software/gawk/manual/gawk.html#index-system_0028_0029-function …
answered Mar 7 '18 by RomanPerekhrest
0
votes
awk approach using multidimensional arrays and asort function: awk 'NR==1{ h=$0; } NR>1 { b[NR]=$0;a[$1][length(a[$1])+1]=$3; } END { print h,"diff"; for (i in a) { asort(a[i …
answered Apr 13 '17 by RomanPerekhrest
8
votes
The shortest one: awk -F'\t' '!a[$1]++' file The output: A 5 B 2 C 4 D 99 !a[$1]++ - ensures line printing on encountering the first unique value of the 1st column …
answered Jun 21 '17 by RomanPerekhrest
11
votes
The vertical bar char | is treated as special character in your case and should be escaped: echo "f1||f2" |awk -F'\\|\\|' '{print $1}' f1 As an alternative you may put | into the character class: echo "f1||f2||f3" |awk -F'[|]{2}' '{print $3}' f3 …
answered Sep 12 '17 by RomanPerekhrest
1
vote
Short awk approach: awk -F'|' 'NR==1{ h=$1; print }NF>1 && NR>1 && $0!~"^"h' file -F'|' - treat | as field separator NR==1{ h=$1; print } - on encountering the 1st record assign the 1st header …
answered Nov 17 '17 by RomanPerekhrest
5
votes
find + GNU awk solution: find . -type f -name "*.css" -exec gawk -i inplace \ '{ for (i=1; i<=NF; i++) if ($i ~ /^[0-9]+\.[0-9]+rem/) { v=$i/2; sub(/^[0-9]+\.[0-9]+/, "", $i); $i=v $i } }1' {} \; …
answered Mar 14 '18 by RomanPerekhrest
1
vote
Short awk approach: awk '{ print ($2=="q"? $1:$2) }' file $2=="q"? $1:$2 - ternary condition, means: if the expression $2=="q is evaluated as true - print the left operand $1, otherwise - print …
answered Oct 18 '17 by RomanPerekhrest
1
vote
Python 3.x approach (just the alternative solution): sum_digits.py script: import sys with open(sys.argv[1], 'r') as f: for l in f: print("sum", sum(int(d) for d in l if d.isdigit())) …
answered May 10 '17 by RomanPerekhrest
1
vote
Awk solution (independent of item positions): awk 'function get_item(name){ match($0, name"=[^[:space:]]+"); return substr($0, RSTART, RLENGTH) } { print get_item("src …
answered Jan 3 '18 by RomanPerekhrest
2
votes
awk solution: awk 'NR>1{ k=$3*2; f=""; if($2>k) f="s1" OFS $2; else if($4>k) f="s3" OFS $4; if (f!="") print $1,f }' OFS='\t' file The output: g1 s1 20.17 g2 s3 94.0 g7 s1 2.28 …
answered Jun 22 '17 by RomanPerekhrest
1
vote
Awk script: extract_pat_space.awk contents: $0 ~ "^#" pat{ f = 1; hash = 0 } f { print } NF == 1 && $1 == "#"{ if (++hash == 2) { f = hash = 0 } } Usage (for both patterns): $ awk -f … extract_pat_space.awk -v pat="List" file > list_of_objects.txt $ awk -f extract_pat_space.awk -v pat="Reports" file > reports.txt Results: $ cat list_of_objects.txt #List of Objects # # Headers …
answered Jun 27 '18 by RomanPerekhrest
0
votes
Awk solution: awk 'NR == FNR { a[$1] = $2 OFS; next } $2 in a { a[$2] = a[$2] (a[$2] ~ /\t$/? "" : ",") $1 } END { for (i in a) print i, a[i] }' OFS='\t' file1 file2 The output: bhy 30 … c abc 10 a,d,e xyz 20 b,f For your last condition use the following modification: awk 'NR == FNR { a[$1] = $2 OFS; next } $2 in a { a[$2] = a[$2] (a[$2] ~ /\t$/? "" : ",") $1 } END { for (i in a) print i, a[i] (a[i] ~ /\t$/? "Not_Available" : "") }' OFS='\t' file1 file2 …
answered May 30 '18 by RomanPerekhrest
1
vote
B is the 1st field $1 in your input line. Just start processing from the 2nd field: awk 'NR==5{ for(i=2; i<=NF; i++) sum+=$i; print sum/(NF-1) }' file …
answered Mar 19 '18 by RomanPerekhrest

15 30 50 per page