Linked Questions

3
votes
2answers
11k 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): --------...
-1
votes
2answers
4k 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
2k 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
854 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 ...
0
votes
2answers
759 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 ...
1
vote
1answer
359 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
0answers
493 views

awk search for string containing forward slash in variable [duplicate]

I'm searching for a string in a massive XML file. Snip: <sv:node sv:name="notfound"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>hst:component&...
0
votes
1answer
128 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
89 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
84 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 ...
1
vote
1answer
44 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 ...
2
votes
1answer
22 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 ...
0
votes
0answers
33 views

Bash - Remove line from /etc/fstab - advice [duplicate]

First post - go easy on me:) Was rewriting bash script to delete lines in /etc/fstab. I can get it to work with the "echo". Question: Why cant it do with with awk? echo "Code:" if [ "$quit" ==...
0
votes
0answers
23 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 ...
0
votes
2answers
6k 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