Skip to main content

All Questions

3 votes
2 answers
4k views

Define a variable to awk pattern matching from bash

I am trying to grab 100 lines after the text "time: X" with X in {0,40,80,...,200}. Here is what I have so far: #!/bin/bash start=1 end=5 for i in $(seq $start $end);do j=$(($i*40)) awk '/time: ...
user164723's user avatar
2 votes
4 answers
6k views

Why does the grep command ignore the period in the search string?

The command that I am using: find . -type f -name "*.sql" -exec grep -i -l 'schema_name.' {} + What I want to search is all the files which contain schema_name.. But the find command is ignoring the ...
romil gaurav's user avatar
1 vote
1 answer
2k views

regular expression : with a variable

arrFormat=( jpg jpeg bmp tiff png ) varExtension="jpg" for elem in "${arrFormat[@]}" do   echo "${elem}"   # do something on $elem # done #for i in $( find -E . -iregex '.*\.($arrFormat)' ) ; do #...
kris's user avatar
  • 163
3 votes
1 answer
3k views

cshell alias: How to use nested single quotes(') in in cshell alias

I am trying below alias in cshell: alias sll 'ls -l \!* | grep -oE '[^ ]+$' | paste -s | xargs ls -l' For this CSH says, Illegal variable name. If I use \$, alias will be set without any error. But ...
BluVio's user avatar
  • 155
0 votes
3 answers
838 views

significance behind escaping parentheses in expr match

Can anybody give me the difference between the following two commands in the context of escaping parentheses, or refer some document that would clear my doubt. string=abcABC123ABCabc $ echo `expr ...
Sudhish Vln's user avatar
1 vote
1 answer
3k views

What does a backslash represent when searching for decimals

I want to understand what the backslash represents in this command. grep "\.900983" table I know what the command does, it searches for the 900983 value in table, I'm just not sure of the purpose of ...
Katz's user avatar
  • 1,071
3 votes
2 answers
2k views

How to escape metacharacters for egrep like metaquote from Perl?

Perl has a function called metaquote() to escape all special characters for a regular expression. Is there an equivalent technique for egrep? Example: If I am searching for the string abc.def.ghi, I ...
kevinarpe's user avatar
  • 687
0 votes
0 answers
358 views

swap strings of text inside vim using regex

I am working with a file where I need to swap "string A" and "String B's" locations simultaneously with a regex inside the vim. Here is an example line of code: succ_1st=`grep 'resulted in successful ...
user53029's user avatar
  • 2,843
4 votes
1 answer
1k views

Match pattern \\\" using grep

I have a json string inside json. This got encoded multiple times and I ended up with many escape backlashes: \\\". The much shortened string looks like, '[{"testId" : "12345", "message": "\\\"the ...
user avatar
0 votes
1 answer
264 views

What does "\(\)" stand for in this command: grep("-(mean|std)\(\)", x[,2])

Need to know about the function of \(\) in grep("-(mean|std)\(\)", x[,2])
Rishabh Verma's user avatar
6 votes
1 answer
678 views

Why can't I escape the braces "]" in sed?

Question: Why can't I escape the "]"? $ printf "*#$@~\!&*()[]\n" *#~\!&*()[] $ printf "*#$@~\!&*()[]\n" | sed 's/[*#$@~!&*()\[\]]//g' *#~\!&*() $
LoukiosValentine79's user avatar
1 vote
2 answers
2k views

How to search parenthesis by ack

I want to search for a parentheis ( using ack, but neither using ( nor \( worked. The first one ("(") is recognized as a multiple line command. The second one ("\(") is treated as an invalid regular ...
ironsand's user avatar
  • 5,265
3 votes
3 answers
703 views

Why awk understand FS="*" but not for FS="-*-"?

I got a test file, its content is: a -*- b I used awk 'BEGIN {FS="*"} {print $2}' test, it prints out - b Correct! But when I use awk 'BEGIN {FS="-*-"} {print $2}' test, I got: * I know that FS ...
ZengJuchen's user avatar
  • 7,677
1 vote
2 answers
2k views

Why does regex with \\$\{ work with egrep, but not with sed?

Given a text like this ./RFF_09 -f${FILE} -c${COND} inside a file, this egrep command will correctly match: egrep './RFF(.*) (.*)-c\\$\{COND\}' file but this sed command will not sed -n "s:'./RFF(...
Chaos_99's user avatar
  • 123
1 vote
0 answers
76 views

Take the unknown contents of variable as literal in sed [duplicate]

I have two files: a.patterns contains patterns in a one per line way "`" "^" "<" "<(" "<)" "<[" "=" ">" "_;|^+*+?@" and b.data contains comma separated values. 1,1,0,"*",1 2,1,1,"*",...
dr.doom's user avatar
  • 111

15 30 50 per page