Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • I want to wrap the gawk solution into a script like: #!/bin/bash echo read -p "Please enter your file name: " infile echo read -p "Please enter the column number with the mutations: " column echo read -p "Please enter a file name for the results: " outfile gawk -F '\t' -v OFS='\t' 'match($column, /[[:digit:]]+/, m) {$(++NF) = m[0]} 1' $infile > $outfile How do I pass a user defined variable like "$column" to gawk for the column to match? Commented Feb 16, 2016 at 5:14
  • Like this : gawk - F '\t' -v OFS='\t' -v col="$column" 'match($col, ... - - you should add some verification the column variable is a number since awk handles non-number looking strings like the number zero so you could be matching against $0 Commented Feb 16, 2016 at 11:34