Sample Header Ad - 728x90

How to use 'awk' in tcl script?

1 vote
2 answers
4928 views
It might be trivial, but I am facing problem in using awk for simple purpose like printing first row in a file using tcl script. I used the following command inside tcl script: awk '/manager/ {print $4}' sourcefile.txt But it gives error : extra characters after close braces sourcefile.txt: ajay manager account 45000 sunil clerk account 25000 varun manager sales 50000 amit manager account 47000 tarun peon sales 15000 deepak clerk sales 23000 sunil peon sales 13000 satvik director purchase 80000 I want to print the specific column of the row which contains the searched string; here the searched string is "manager" and output I want is 4th column, So, the required output: 45000 50000 47000 The awk command works well in the terminal; but shows error while I put it inside a file, and then execute the file. I got the solution up to this. Thanks for answering! One more doubt, Suppose I have value "manager" stored in a variable "var". And I want to search using that variable: can I use this? awk {/$var/ {print $4}} sourcefile.txt I am not able to find a way. The above command does not give me result.
Asked by Manisha Kuhar (67 rep)
Jun 17, 2020, 05:24 AM
Last activity: Jun 18, 2020, 04:12 AM