[Solved] Grep text between patterns using bash [closed]

Sed can do it as follows: sed -n ‘/^======/{:a;N;/\n——/!ba;/score +/p}’ infile ====== Ann Smith score + —— where -n prevents printing, and /^======/ { # If the pattern space starts with “======” :a # Label to branch to N # Append next line to pattern space /\n——/!ba # If we don’t match “——“, branch to … Read more

[Solved] How can I manipulate text in bash? [closed]

With awk: awk ‘BEGIN{FS=”[ ,]”; OFS=”,”} {for (i=2; i<=NF; i++) print $i,$1}’ file Output: foo,ted bar,ted zoo,ted ket,john ben,john See: 8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR solved How can I manipulate text in bash? [closed]

[Solved] Return not so similar codes from a single group [closed]

I would harness GNU AWK for this task following way, let file.txt content be 9003103 9003103 9003978 9003979 9003763 9003728 9003543 9003543 9003543 then awk ‘BEGIN{RS=””}{diff=$NF-$1;diff=diff>0?diff:-diff}diff>NF’ file.txt gives output 9003763 9003728 Explanation: I set RS to empty string to provoke paragraph mode, thus every block is treated as single line, then for each block I … Read more

[Solved] Fastest way to read file searching for pattern matches

‘grep’ contains decade’s worth of optimizations, and re-implementing it in any programming language, not just Python, will be slower. *1 Therefore, if speed is important to you, your technique of calling ‘grep’ directly is probably the way to go. To do this using ‘subprocess’, without having to write any temporary files, use the ‘subprocess.PIPE’ mechanism: … 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