Linked Questions

58
votes
3answers
92k 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 ...
5
votes
1answer
2k views

Using bash variable with escape character in awk to extract lines from file

I am writing a bash script (just learning bash) to extract some lines from a file based on two patterns. The first pattern is just a sentence ending in a colon. The second pattern is a * repeated N (...
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): --------...
3
votes
2answers
11k 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 ...
3
votes
1answer
90 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 ...
3
votes
2answers
533 views

How to use command-line argument as awk regex matching expression?

I have the following awk script: #!/bin/awk -f BEGIN { FS = ""; } value ~ "MYVALUE" # silly test { print "1 - " substr($0, 235, 12); } $235 ~ "M" { print "2 - " substr($0, 235, 12); } ...
2
votes
2answers
22k 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}' ...
2
votes
1answer
378 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
7answers
658 views

How do we use sed to replace specific line with a string variable?

Lets say for example I have a file.txt containing 3 lines: hello hello hello I have a variable called line=1 and a variable string substitute=hello1. I want to replace the string in the line ...
1
vote
3answers
96 views

Simple shell script unable to go through thousands of files; starts fine, but throws “unexpected EOF while looking for matching `”`" after some time

Shell Script in Question Let me explain what I am trying to do by e.g. so you can understand better. Let's say I have 100 .torrent files in a directory. 2 of them will download xxx.epub and yyy.epub ...
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
vote
1answer
797 views

awk argument $1,$2 conflict with bash input arguments

I would like to add some awk commands to a bash script. The bash script takes a few inputs, and inputs are passed by $1, $2 and etc. When I call awk, I also want to use $1 to define a position in ...
1
vote
1answer
704 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 ...
1
vote
1answer
3k views

use awk with input from a variable

i need to fetch n+9th line from the occurance of a specific word which is store in variable i from a file LIST.txt Below is the command Used_pages=`awk '/${i}/{nr[NR+9]}; NR in nr' LIST.txt` it ...
1
vote
1answer
80 views

When using AWK with a variable pattern, can't get IF ELSE statement working

The AWK statement uses the variable $ip to search each line, but I need to print the variable $ip NOT FOUND in the ELSE statement for ips that are not found in the config. Can't get it to work with ...

15 30 50 per page