Linked Questions

1
vote
0answers
32 views

Escape slash in variable for awk pattern [duplicate]

I want to get all lines within specified date. The following pattern prints 15/Jan however when used for awk it gives Fatal Unmatched error. pattern=$(date -d "2 day ago" +'%d/%b') awk '$4 ~ ...
-1
votes
1answer
53 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 ...
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 ...
1
vote
7answers
733 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
97 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
805 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 ...
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 (...
58
votes
3answers
93k 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 ...
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 ...
0
votes
2answers
816 views

How to grep variable pattern which is in first column [duplicate]

I want to grep variable pattern which is in first column. $ cat test.txt abc.xyz abc.def pqr.tap pqr.abc abc.mnp mnp.abc abc.pqr abc.mob If variable pattern is abc then output should be abc....
2
votes
1answer
380 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
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 ...
1
vote
2answers
478 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
2answers
289 views

How can I search matching pattern (stored in a variable) in a file using awk?

I have a log file in which I need to check if there are any error messages, if there are, extract the error message to another file. Like this I may have error file for the different file have ...
0
votes
0answers
649 views

invalid char '@' in expression awk output

I have an awk command on ksh script, the command extract fields from a log file to then struct them in new one. ultimate=$(grep -oP 'Time:\K.*' $log2 | column -t | awk '{print $3,"/","'"$month"'","/",...

15 30 50 per page