[Solved] Add an exclude array to an existing awk code

EDIT: OP told there could be words like “a” too so handle that case adding following now. awk ‘ BEGIN{ s1=”\”” num=split(“McCartney feat. vs. CD USA NYC”,array,” “) for(k=1;k<=num;k++){ temp=tolower(array[k]) ignoreLetters[temp]=array[k] } num=split(“a the to at in on with and but or”,array,” “) for(i=1;i<=num;i++){ smallLetters[array[i]]=array[i] } } /TITLE/{ for(i=2;i<=NF;i++){ front=end=nothing=both=”” if($i~/^”/ && $i!~/”$/){ temp=tolower(substr($i,2)) front=1 … Read more

[Solved] Problem replacing numbers with words from a file

this can be accomplished in a single awk call. associate numbers with champions in an array and use it for replacing numbers in second file. awk ‘BEGIN{FS=OFS=”,”} NR==FNR{a[$1]=$2;next} {$1=a[$1];$2=a[$2]} 1’ champions.csv top.csv Olaf,Annie,3 Galio,Annie,5 Twisted Fate,Annie,6 Xin Zhao,Annie,1 Urgot,Annie,10 LeBlanc,Annie,9 Vladimir,Annie,11 Kayle,Twisted Fate,12 LeBlanc,Xin Zhao,2 Galio,Galio,6 in case there should be some numbers in top.csv … Read more

[Solved] looping over AWK commands doesn’t work [duplicate]

Because your awk program is in single quotes, there will not be any shell variable expansion. In this example: awk ‘tolower($0)~/^alphabet/{print}’ titles-sorted.txt > titles-links/^alphabet.txt …you are looking for the lines that begin with the literal string alphabet. This would work: awk “tolower(\$0)~/^$alphabet/{print}” titles-sorted.txt > titles-links/$alphabet.txt Note several points: We are using double quotes, which does … Read more

[Solved] grep values and re-arranging the file

Try this awk: awk -F'”‘ ‘NR%2{p1=$4;next} {print p1 “https://stackoverflow.com/” $4}’ Test: $ awk -F'”‘ ‘NR%2{p1=$4;next} {print p1 “https://stackoverflow.com/” $4}’ file abc/123abc bac/bac123 cde/cd123 b4u/b4u234 2 solved grep values and re-arranging the file

[Solved] Extract data from txt file and create new file based on specific text dynamically

Here is an easy-to-read solution with Bash and grep: #!/bin/bash while read line ; do if FILE=$(grep -P -o ‘[a-z]*\.txt(?= – Starting)’ <<< “$line”); then F=”$FILE” fi if ! grep ‘\*\*\*\*’ <<< “$line” ; then echo “$line” >> “$F” fi done It gives the following result $ cat file.txt ****************** abc.txt – Starting point ******************** … Read more

[Solved] Shell scripting to find the delimiter

To count the number of columns with awk you can use the NF variable: $ cat file ABC|12345|EAR PQRST|123|TWOEYES ssdf|fdas,sdfsf $ awk -F\| ‘NF!=3’ file ssdf|fdas,sdfsf However, this does not seem to cover all the possible ways the data could be corrupted based on the various revisions of the question and the comments. A better … Read more

[Solved] Select required field from line [closed]

Here you go: awk ‘{a=$1;c=$4;getline;b=$3;getline;d=$4;print a,b,c,d}’ test 12 17 19 You does not say how to get the result!!! awk ‘ # start { a=$1 # from first line set a=”test” c=$4 # from first line set c=17 getline # get next line b=$3 # from second line set b=12 getline # get next line … Read more

[Solved] Extracting the values within the square braces

In GNU awk: $ awk -F”[][]” ‘{split($2,a,”-“); for(i=a[1];i<=a[2];i++) print $1 i $3}’ file app-server-l112.test.com app-server-l113.test.com app-server-l114.test.com app-server-l115.test.com server-l345.test.com server-l346.test.com server-l347.test.com server-l348.test.com dd-server-l2.test.com dd-server-l3.test.com dd-server-l4.test.com split to fields by [ and ] using FS use split the get the range start (a[1]) and end (a[2]) iterate the range with for and output There is no checking … Read more