Linked Questions
37 questions linked to/from Pass shell variable as a /pattern/ to awk
4
votes
2
answers
17k
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):
--------...
3
votes
2
answers
12k
views
How to insert bash variables in awk? [duplicate]
How to insert bash variables in awk (for example i need to do in in some for loop - like this: in first iteration use awk to search string by first column, next by second column and so on with using ...
0
votes
2
answers
11k
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
1
answer
6k
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 ...
2
votes
1
answer
1k
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
votes
1
answer
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
1
answer
952
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
2
answers
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 ...
3
votes
1
answer
246
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 ...
1
vote
2
answers
1k
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 ...
0
votes
1
answer
260
views
Pass variable to context match awk [duplicate]
I am trying to extract context from a file with awk from a start pattern until an end pattern.
Here is simplified sample input to reproduce:
$ cat file
1
2
3
4
5
6
When I pass the start pattern ...
1
vote
1
answer
529
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
votes
1
answer
182
views
pass value to awk in shell script [duplicate]
So I have my targets array which is a bunch of IP read from a file, now I am trying to cat a file that contains my IP and results from ssh command, ut because I am trying 3 different passwords on ...
0
votes
1
answer
198
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
1
answer
60
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 ...