[Solved] parse file in perl using awk commands
[ad_1] awk ‘{ a[$1]+=$2+$3 } END { for (i in a) print i, a[i] }’ input.txt > op.txt [ad_2] solved parse file in perl using awk commands
[ad_1] awk ‘{ a[$1]+=$2+$3 } END { for (i in a) print i, a[i] }’ input.txt > op.txt [ad_2] solved parse file in perl using awk commands
[ad_1] Since you didn’t provide any details, here is the boiler plate. $ sed -n ‘/start/,/end/p’ file > outputfile or $ awk ‘/start/,/end/’ file > outputfile 3 [ad_2] solved Script to grep on range of start/end text [closed]
[ad_1] awk ‘ /connection from/{ nr=NR; conn[nr]=$NF; auth_counter[nr]=0; next; } { auth_counter[nr]++; auth_msg[nr]=$NF; } END{ for(i in auth_counter) if(auth_counter[i]==1) print conn[i], auth_msg[i] }’ file x.x.x.x BBB y.y.y.x CCC x.x.x.a ZZZ [ad_2] solved awk how to parse based on pattern but skip multiple similar lines and accept only single line occurence [closed]
[ad_1] Since it’s not clear what you’re trying to do: If you expect the following output: yypasswd then do ps -ef | grep yypasswd | awk ‘{print $8}’ if you want the following output: testacc 25124194 2512312620 0 08:00:53 pts/0 0:00 then do ps -ef | grep yypasswd | awk ‘{print $1, $2, $3, $4, … Read more
[ad_1] Here’s a solution using awk awk -F ‘;’ ‘{same=1; for (i=3;i<NF;i++) { if ($i != $2) { same=0 } }; if (same == 1) {print $0}}’ file Here’s how it works ‘{ same=1; #assume all fields are the same for (i=3;i<NF;i++) { #for each field after the second if ($i != $2) { same=0 … Read more
[ad_1] You should have been more clearer when you raise the problem. Do not add test cases later You can try this, I have modified the third field to last but one. But credit to @Kaz ~> more test SER1828-ZXC-A1-10002 SER1878-IOP-B1-98989 SER1930-QWE-A2-10301 SER1930-QWE-A2-10301 SER1930-QWS_GH-A2-10301 SER1930-REM_PH-A2-10301 SER1930-REM-SEW-PH-A2-10301 SER1940-REM-SPD-PL-D3-10301 ~> awk -F- ‘BEGIN { OFS=”-” } { … Read more
[ad_1] I’m assuming the input is always two columns, the first column contains the column headers of the output repeated over and over, and that the output may contain one or more columns. $ cat t.awk { sep = (FNR % n == 0) ? “\n” : ” ” } NR==FNR { printf $1 sep; … Read more
[ad_1] awk -F ‘|’ -v ‘OFS=|’ ‘{$13 = $16; NF -= 3; print}’ file or perl -F’\|’ -ne ‘splice(@F, 12, 3); print join(“|”, @F)’ file 1 [ad_2] solved How to match and remove a string of characters in a pattern
[ad_1] If you won’t have more than one of the pattern on a single line, I’d probably use sed: sed -n -e ‘s%.*https://\([-.0-9A-Za-z]\{1,\}\.[A-Za-z]\{2,\}\).*%\1%p’ Given the data file: Nothing here Before https://example.com after https://example.com and after Before you get to https://www.example.com And double your https://example.com for fun and happiness https://www.example.com in triplicate https://a.bb and nothing here … Read more
[ad_1] It’s not clear from your question as you didn’t provide sample input/output we could test against but it SOUNDS like all you’re trying to do is this: $ cat tst.awk BEGIN { split(“7 10 15 12 4″,w) FPAT=”[^,]*|\”[^\”]*\”” } { gsub(/””/,RS) for (i=1;i<=NF;i++) { gsub(/”/,””,$i) gsub(RS,”\””,$i) printf “<%-*s>”, w[i], substr($i,1,w[i]) } print “” } … Read more
[ad_1] Assumptions: we want to match on lines that start with the string number we will always find 2 matches for ^number from the input file not interested in storing values in an array Sample data: $ cat file.dat number1: 123 not a number: abc number: 456 We’ll use awk to find the desired values … Read more
[ad_1] You didn’t ask for Tcl code, but here’s one way to do it. It could be prettier, but it works. set data { A1 1 2 a1 B1 3 4 b1 C1 5 6 c1 } set ns {} foreach {- a b -} $data { lappend ns $a $b } set a 0 … Read more
[ad_1] As I said in my answer to your previous question, you can fix this easily by using single quotes on the inside. PHP Code <?php $eff=40; $pos=34; $i = ‘hello’; $line=exec(“tail $i.dssp -n $eff | awk -F’ ‘ -v var=$pos ‘{if ($2==var) print FNR}'”); print “$line\n”; ?> Sample Input (hello.dssp): foobar 34 Sample Output: … Read more