Linked Questions

3
votes
2answers
13k views

How to pass shell variable to an awk search pattern? [duplicate]

In my bash script I have a variable that I am trying to pass to a pattern to search for using awk. However what I expected to happen is not working. I have the following text file (text.txt): --------...
0
votes
2answers
6k views

How to use a variable inside an awk statement? [duplicate]

I have a script like this #!/bin/ksh echo "Enter the matching pattern" read pattern path= /home/siva/ echo "Navigating to $path" cd $path cat filename|awk '/$pattern/ {for (i=1; i<=10; i++) {...
1
vote
1answer
3k views

make awk print the line that match a variable and the next n lines and use a variable in awk [duplicate]

With an array of elements, and an input-file I want to loop through the array and match each element with the input-file. I then want to get the line in the input-file where this element is occurring ...
-1
votes
1answer
1k views

AWK and Bash Scripting [duplicate]

How to use a value of a variable in awk? Something like this: filename = "test.txt" ls -l | awk '{ if ($9 == filename) print("File exists")}' I can't use $ in awk to access the value of that ...
1
vote
1answer
676 views

Pass Shell variable to awk [duplicate]

I realize this has been asked many times and many of the answers seam well written, but I'm missing something with my little task. Trying to pass a Shell variable (an argument in this case) to awk to ...
0
votes
2answers
1k views

using awk with variables [duplicate]

I am making a word list from all the words typed into a program that will be working with the text entered into it. I want to use a stream editor like sed or awk to search the first word of every ...
2
votes
1answer
363 views

Pass parameter to Bash function which will serve as a pattern to awk [duplicate]

I would like to know how to pass a argument to a Bash function which would consequently serve as a pattern to awk. I have read several Q/As which tend to answer the same question, however, I am ...
1
vote
1answer
385 views

how to use variable with awk [duplicate]

we have the following file cat /tmp/hive.conf "hive-exec-log4j2" : { "tag" : "TOPOLOGY_RESOLVED", "version" : 2 }, "hive-interactive-env" : { "tag" : "...
1
vote
2answers
440 views

how to awk user input [duplicate]

I'm trying to match a pattern and then print out two lines after it. I'm successfully able to do it with the following code. awk '/'202404'/{c=3}c&&c--' consolelog.log > testing.txt I'm ...
3
votes
1answer
69 views

Passing argument to AWK [duplicate]

I have the following AWK command which works well. awk -v RS="\n+?[$]{4}\n+?" '/HMDB0000008/' test.xt However what I want is to be able to call it from the command line and pass an argument ...
0
votes
1answer
163 views

Pass a variable in another variable within an awk [duplicate]

I have the below variables: grep_line_new_file='create table "informix".issue' new_file_below=`awk 'BEGIN { FS="\n[()]"; RS=";" } /$grep_line_new_file/ { print ")"$NF";"}' test` Inside test file I ...
1
vote
1answer
45 views

How to make variable be taken into account [duplicate]

#!/bin/bash awk 'NR!~/^(1|$q+2|$q+3)$/' deltay.txt > yota.txt q is an integer obtain from a previous process in the script, and I need to erase lines one, the q+2 an q+3, but that command just ...
0
votes
0answers
27 views

pattern matching to content of variable using awk [duplicate]

**********NB -i have read previous posts that look like duplicates but I cannot get this to work, Id really appreciate an explicit answer ********** I know this is a duplicate but I have read the ...
57
votes
3answers
91k views

How to show lines after each grep match until other specific match?

I know that by using the "-A NUM" switch I can print specific number of trailing lines after each match. I am just wondering if it's possible to print trailing lines until a specific word is found ...
0
votes
2answers
21k views

awk + set variable inside the awk

the following simple bash script print the row number ( from the file - list.txt ) function get_row { [[ $1 = 1 ]] && awk '{print $1}' list.txt [[ $1 = 2 ]] && awk '{print $2}' ...

15 30 50 per page