AWK: Access captured group from line pattern
If I have an awk command pattern { … } and pattern uses a capturing group, how can I access the string so captured in the block? 7 Answers 7
If I have an awk command pattern { … } and pattern uses a capturing group, how can I access the string so captured in the block? 7 Answers 7
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for … Read more
Given the following command, echo “1: ” | awk ‘/1/ -F “:” {print $1}’ why does AWK output: 1: ? 8 Answers 8
I want to shuffle the lines of a text file randomly and create a new file. The file may have several thousands of lines. How can I do that with cat, awk, cut, etc? 19 Answers 19
I found some ways to pass external shell variables to an awk script, but I’m confused about ‘ and “. First, I tried with a shell script: $ v=123test $ echo $v 123test $ echo “$v” 123test Then tried awk: $ awk ‘BEGIN{print “‘$v'”}’ $ 123test $ awk ‘BEGIN{print ‘”$v”‘}’ $ 123 Why is the … Read more
This line worked until I had whitespace in the second field. svn status | grep ‘\!’ | gawk ‘{print $2;}’ > removedProjs is there a way to have awk print everything in $2 or greater? ($3, $4.. until we don’t have anymore columns?) I suppose I should add that I’m doing this in a Windows … Read more
I’m using jq to parse a JSON file as shown here. However, the results for string values contain the “double-quotes” as expected, as shown below: $ cat json.txt | jq ‘.name’ “Google” How can I pipe this into another command to remove the “”? so I get $ cat json.txt | jq ‘.name’ | some_other_command … Read more
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 8 years ago. Improve this question What is the difference between awk and sed ? What kind of application are best … Read more
I often need to kill a process during programming. The way I do it now is: [~]$ ps aux | grep ‘python csp_build.py’ user 5124 1.0 0.3 214588 13852 pts/4 Sl+ 11:19 0:00 python csp_build.py user 5373 0.0 0.0 8096 960 pts/6 S+ 11:20 0:00 grep python csp_build.py [~]$ kill 5124 How can I extract … Read more
Is there a “canonical” way of doing that? I’ve been using head -n | tail -1 which does the trick, but I’ve been wondering if there’s a Bash tool that specifically extracts a line (or a range of lines) from a file. By “canonical” I mean a program whose main function is doing that. 19 … Read more