All Questions
Tagged with pattern-matching linux
15 questions
1
vote
0
answers
97
views
does "find -name " matches the whole path or just the basename?
I was getting inconsistent results with pattern matching using -name, -iname, especially when looking for files -type f or directories type -d. Can someone explain under which circumstances -name ...
2
votes
2
answers
2k
views
Sed based on 2 words, then replace whole line with variable
I have a txt file looking like this,
1:Ana:apple:08:00:wait
1:Joe:banana:08:30:wait
1:Oscar:orange:08:45:ready
1:Monica:apple:08:50:ready
1:Mark::orange:ready
I have to find only the first line that ...
0
votes
1
answer
657
views
select lines in file with same string pattern
Let´s suppose I have the following file.txt:
asiub
sj
abq
b aia
ainp oo
test = 123d
sub ,.
aiba 87ab
test = 129szs bq
test = aqua
ayqvq 133s
I want to print only the lines of file.txt that contain ...
2
votes
1
answer
8k
views
to match the case insensitive pattern in if condition
There could be below 2 cases in a file: a.txt:
case 1:
V1=last #case insensitive
V2=Last #case insensitive
case 2:
V1=last #case insensitive
V2=LastNum #case insensitive
I need to check if ...
2
votes
8
answers
2k
views
Print a portion of a lines in a text file between predefined tags
I have a file like the following
<g> Good wheatear </g> other parts of line
<g> The farm land is to be sold </g> other parts of line
<g> knock knock </g> other ...
-1
votes
1
answer
137
views
Custom data formatting and pattern matching
I am trying to format custom data using pattern match. I am not getting expected format. Though I am not shell script savvy but I was able to build a script based on references from multiple sources ...
0
votes
1
answer
233
views
find a file based on date mentioned in parameter
I have a requirement to find a file based on date provided in the parameter.
For example, I have these files:
XYZ.ABC.M.20200615180200.batch
XYZ.ABC.M.20200616180200.batch
XYZ.ABC.M.20200617180200....
1
vote
1
answer
464
views
My grep for a process returns multiple strings with similar name
I have a script that checks processes on our Linux servers.
An example would be we have a component named ebond-dbreader-bbg on server 1 and also a component named ebond-dbreader-bbg-cbrt on server 1....
0
votes
4
answers
2k
views
AWK: how to extract pattern between 2 custom field separators regardless of pattern's position on the line?
Here is a fragment of a line in file:
LN=FINE FOODS & PHARMACEUTICALS NTM, MIC=XAIM, RIC=FF.MI, SG=MA1
I am interested in extracting the value of tag "MIC", i.e. my desired output is:
...
-2
votes
3
answers
3k
views
What is command to redirect the lines from one file to another file
I want to redirect the lines which contain "hello" from file1 to file 2 in Unix. What is the command used here?
0
votes
0
answers
80
views
Comparing two columns of one file with two columns of another file. Python or Bash?
So guys have two files, both of them are tab-separated text files, trying to merge both the files based on two columns. The two files are unsorted and doesn't contain a header. Another thing is that ...
2
votes
3
answers
483
views
How to find the last occurrence of a string in column 1 and replace the corresponding value in column 3?
I have three columns in a file as such:
apple1 10109283 20012983
apple1 10983102 10293809
apple1 10293893 2349823049
apple10 109283019 109238901
apple10 ...
0
votes
2
answers
460
views
How to grep a string with any two numbers that match or that have the first number one less than the second number?
I have a tab delimited file with four columns. I would like to grep for the lines that have a specific pattern in column 1, where it says apple M of N.
I only want to extract the lines that have the ...
2
votes
0
answers
58
views
why does recursive searching with grep print fewer lines when using \bSTRING\b compared to the -w option?
There are two ways to read all files under the current working directory:
grep -rw pip | wc -l
grep -r "\bpip\b" | wc -l
Assuming 1 and 2 both search the working directory for the whole word "pip", in ...
1
vote
4
answers
1k
views
How to extract word which has only numbers separated by 'dot'
From below lines
abcd efgh ijhk lmn opqrs 9.0.8.2c tuv wxyz
abcd efgh ijhk lmn opqrs 8.1.3.9b
How to extract only
9.0.8.2c
8.1.3.9b