awk

Awk RegEx returning nada?

拜拜、爱过 提交于 2020-12-15 06:43:49
问题 So I have this text in a file named version.php : <?php $OC_Version = array(20,0,1,1); $OC_VersionString = '20.0.1'; $OC_Edition = ''; $OC_Channel = 'stable'; $OC_VersionCanBeUpgradedFrom = array ( 'nextcloud' => array ( '19.0' => true, '20.0' => true, ), 'owncloud' => array ( ), ); $OC_Build = '2020-10-24T08:39:55+00:00 89d88b3ea5b4049355e3c49d121f82e5e62bfc44'; $vendor = 'nextcloud'; and I'm trying to get awk to return just the version number from the line: $OC_VersionString = '20.0.1';

Use of Awk filter to get the students records details in descending order of total score

大憨熊 提交于 2020-12-13 03:40:30
问题 Student details are stored in a file system as follows: Roll_no,name,socre1,score2 101,ABC,50,55 102,XYZ,48,54 103,CWE,42,34 104,ZSE,65,72 105,FGR,31,45 106,QWE,68,45 Q.Write the unix command to display Roll_no and name of the student whose total score is greater than 100 the student details are to be displayed sorted in descending order of the total score. total score as to be calculated as follows :- totalscore=score1+score2 file also content the header(Roll_no,name,socre1,score2) My

Truncation of strings after running awk script

谁说我不能喝 提交于 2020-12-13 03:39:44
问题 I have this code BEGIN { FS=OFS=";" } { key = $(NF-1) } NR == FNR { for (i=1; i<(NF-1); i++) { if ( !seen[key,$i]++ ) { map[key] = (key in map ? map[key] OFS : "") $i } } next } { print $0 map[key] } I use code in this way awk -f tst.awk 2.txt 1.txt I have two text files 1 .txt AA;BB; 2 .txt CC;DD;BB;AA; I try to generate this 3 .txt output AA;BB;CC;DD; but with this script is not possible because this script return only AA;BB; logic: The above just uses literal strings in a hash lookup of

Truncation of strings after running awk script

流过昼夜 提交于 2020-12-13 03:38:36
问题 I have this code BEGIN { FS=OFS=";" } { key = $(NF-1) } NR == FNR { for (i=1; i<(NF-1); i++) { if ( !seen[key,$i]++ ) { map[key] = (key in map ? map[key] OFS : "") $i } } next } { print $0 map[key] } I use code in this way awk -f tst.awk 2.txt 1.txt I have two text files 1 .txt AA;BB; 2 .txt CC;DD;BB;AA; I try to generate this 3 .txt output AA;BB;CC;DD; but with this script is not possible because this script return only AA;BB; logic: The above just uses literal strings in a hash lookup of

awk script for replacing multiple occurances of string pattern in the same line in different files with number matching the string

我怕爱的太早我们不能终老 提交于 2020-12-13 03:32:45
问题 I need a awk script that searches for any string inside <>, if it finds one that it hasn't found before it should replace it with the current value of the index counter (0 at the beginning) and increment the counter. If it finds a string inside <> that it already knows, it should look up the index of the string and replace it with the index. This should be done across multiple files, meaning the counter does not reset when multiple files are searched for the patterns, only at program startup

awk script for replacing multiple occurances of string pattern in the same line in different files with number matching the string

雨燕双飞 提交于 2020-12-13 03:31:46
问题 I need a awk script that searches for any string inside <>, if it finds one that it hasn't found before it should replace it with the current value of the index counter (0 at the beginning) and increment the counter. If it finds a string inside <> that it already knows, it should look up the index of the string and replace it with the index. This should be done across multiple files, meaning the counter does not reset when multiple files are searched for the patterns, only at program startup

Bash how to split file on empty line with awk

不打扰是莪最后的温柔 提交于 2020-12-12 11:37:05
问题 I have a text file ( A.in ) and I want to split it into multiple files. The split should occur everytime an empty line is found. The filenames should be progressive ( A1.in , A2.in , ..) I found this answer that suggests using awk , but I can't make it work with my desired naming convention awk -v RS="" '{print $0 > $1".txt"}' file I also found other answers telling me to use the command csplit -l but I can't make it match empty lines, I tried matching the pattern '' but I am not that

How to use AWK to continuously output lines from a file

让人想犯罪 __ 提交于 2020-12-12 04:07:37
问题 I have a file with multiple lines, and I want to continuously output some lines of the file, such as first time, print from line 1 to line 5, next time, print line 2 to line 6, and so on. I find AWK as a very useful function and I tried to write a code on my own, but it just outputs nothing. Following is my code #!/bin/bash for n in `seq 1 3` do N1=$n N2=$((n+4)) awk -v n1="$N1" -v n2="$N2" 'NR == n1, NR == n2 {print $0}' my_file >> new_file done For example, I have an input file called my

How to use AWK to continuously output lines from a file

人盡茶涼 提交于 2020-12-12 04:05:54
问题 I have a file with multiple lines, and I want to continuously output some lines of the file, such as first time, print from line 1 to line 5, next time, print line 2 to line 6, and so on. I find AWK as a very useful function and I tried to write a code on my own, but it just outputs nothing. Following is my code #!/bin/bash for n in `seq 1 3` do N1=$n N2=$((n+4)) awk -v n1="$N1" -v n2="$N2" 'NR == n1, NR == n2 {print $0}' my_file >> new_file done For example, I have an input file called my

How to extract email headers extending on multiple lines from file

你。 提交于 2020-12-06 20:23:45
问题 I am trying to extract the To header from an email file using sed on linux. The problem is that the To header could be on multiple lines. e.g: To: name1@mydomain.org, name2@mydomain.org, name3@mydomain.org, name4@mydomain.org, name5@mydomain.org Message-ID: <46608700.369886.1549009227948@domain.org> I tried the following: sed -n -e '/^[Tt]o: / { N; p; }' _message_file_ | awk '{$1=$1;printf("%s ",$0)};NR%2==0{print ""}' The sed command extracts the line starting with To and next line. I pipe