[Solved] Print every 3 strings who are start from special symbols
Use this: grep -A 1 -B 1 ‘Server sent’ file.txt | sed ‘/^–$/d’ (OR) grep -C 1 ‘Server sent’ file.txt | sed ‘/^–$/d’ 0 solved Print every 3 strings who are start from special symbols
Use this: grep -A 1 -B 1 ‘Server sent’ file.txt | sed ‘/^–$/d’ (OR) grep -C 1 ‘Server sent’ file.txt | sed ‘/^–$/d’ 0 solved Print every 3 strings who are start from special symbols
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
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
A very quick way is using awk awk ‘BEGIN{RS=””;ORS=”\n\n”}1’ /path/to/your/file > /path/to/new/file How does this work: awk knowns the concept records (which is by default lines) and you can define a record by its record separator RS. If you set the value of RS to an empty string, it will match any multitude of empty … Read more
It sounds like this might be what you’re looking for: $ cat tst.awk BEGIN { FS=OFS=”\t” } NR==FNR { map[$1] = $2 map[$2] = $2 next } FNR==1 { print FS=” ” next } { orig = $0 country = “” gsub(/[^[:alpha:]]/,” “) for (i=NF; i>0; i–) { if ($i in map) { country = … Read more
grep -oP ‘^server\s\K[^ ]+|^[^#]\s+\d+:\K[^:]+’ inputfile pool0 server1 server2 pool1 server3 server4 4 solved Extract specific string between two strings and list the required content
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
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
this one-liner should work: awk ‘NR==FNR{a[$1]=substr($0,92,5);next}($1 in a) {$0=substr($0,1,92) a[$1] substr($0,97)}1’ file file2 1 solved Replace characters 92-97 in position “x” on line
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
Here’s another version if you can’t work with the other answer: awk -vval=2.1 ‘{ # set “val” to the new value for column 3 on first two lines if(NR==1 || NR==2) { # if it’s the first or second line $3=val; # set column 3 to val $2=$3*2.9 # set column 2 to column 3 … Read more
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
awk ‘BEGIN{FS=””;OFS=”https://stackoverflow.com/”}{NF-=3;print}’ file 1/2/2/0/3 6/4/5/8 6/4/5/8 1/0/3/3/6 1/0/3/6/6 1/0/3/6/6 1/0/3/6/6 8/1 2 solved Insert delimiter between digits in linux
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
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