All Questions
75 questions
0
votes
2
answers
131
views
variable assignment doesn't create one same object at least for grep
The problem is as follows (Here I don't use find since it doesn't support double-asterisk wildcard **):
$ FILES=(foo/**/*.suffix bar/**/*.suffix2)
$ grep baz "${FILES[@]}" # works
# I use ...
0
votes
2
answers
44
views
Capture and print on the exact match from a file
I am trying to use grep to match only a specific part of a row in a file.
The file is a huge csv file with some columns containing json with commas so it is hard to figure out which column what I am ...
1
vote
1
answer
96
views
What does "/$" mean to "grep"?
I'm using these two codes below.
ls -lap . | grep -v "/$"
ls -lap . | grep -v "/"
These two give me different outputs in some cases. What does $ mean in that context?
-1
votes
1
answer
45
views
I can't grep some inputrc string
bind -p |grep -E "\\e.\":" work
but
bind -p |grep -E "\\e\\C-.\":" don't work
I tried a lot of combination
1
vote
3
answers
325
views
Return a specific component from a matched grep string?
HI supposed I want to extract only a component of a match, for example up to the first "_"
echo "Ha00030_Z6_L008_I1_001.fastq.gz" | grep -P -o '^H.+?_'
however the above returns, ...
1
vote
1
answer
323
views
Using grep to find all lines containing a character on an even position
So a line in the text file looks like this:
......-...-..--- (hello)
I want to find all lines that only have dots on the even positions. So I think I need to repeat searching for the regex pattern .\....
-1
votes
3
answers
584
views
How to match end of last string in file which does not end with punctuation
I'm trying to search a directory for files which do not end in a period. I'm trying to list the file name with the final ascii character which is not followed by period/ punctuation. I've looked all ...
0
votes
1
answer
599
views
regular expression - command not found on terminal
I am trying to grab my_name 369 from file.txt
I input this grep line with regex but it return an error. I have tried using egrep and it did not work.
Input:
my_name 369 == match
my_name 161 == match
...
5
votes
6
answers
1k
views
split line according to matching pattern in bash
I have the following situation, with two files.
File 1
not relevant = does not matter
some stuff
# var1=1
# var 2 = 2
# var3 = 3
some stuff
File 2
some other stuff
# does not matter either
# var1=a
# ...
0
votes
4
answers
528
views
Changing the name of a file based on a part of its original name that are between the first two instances of a character
I am trying to change the names of my files based on the string between the first two instances of "|". This is what my problem looks like:
>1234|interest1|randomstuff1.txt
>5678|...
1
vote
1
answer
1k
views
-bash: syntax error near unexpected token `(' when using lookahead and lookback?
The use case is rather simple. I have a text file, say the following named eg.txt:
'simple_example': 345, 'to_demonstrate': 232,
'regex': 'is not easy to use'
I am trying to capture the keys:
grep -...
0
votes
1
answer
209
views
I'm trying to understand how to shorten regex
I'm trying to list all directories that are 1GB or larger. I know I could use ncdu, but at the moment, I'm just trying to understand how to shorten regex...
I found this command, du -h . | grep '[0-9\....
3
votes
2
answers
1k
views
Display grep output with line breaks inside a if statement in a bash script
I want to validate a text file with a script.
The file to validate is:
FDFHDK JKL
1545665 152
HDKFHDK UHG
YRYRUBH DFG
867HDKE WER
Valid lines must match the regex '[A-Z]{7}+[[:space:]]+[A-Z]{3}'.
If ...
0
votes
3
answers
3k
views
How can I grep for a block of text that contains certain words across several lines? And how can I do that piped from tail -f?
I want to tail a log file and print ONLY blocks of text that match the regex pattern .*\n.*\nABC(.*\n){1-6}XYZ. In case my regex is wrong already, I want to match this example:
TIMESTAMP HERE
LOG ...
1
vote
2
answers
332
views
Finding a string in a txt of house addresses with number ranges by passing in exact number and street names
Context
I'm a postal worker (mail sorter) and am trying to write a bash script which allows me to input an exact street address and first couple letters of a street name, and have it return the ...