Hi everyone,
I am new to shell scripting, and would appreciate your help on following problem.
I need to search a file for a pattern, then get the number of each line that matches the given pattern.
Then I need to search those specific line numbers from the first file in a second file and print the entire lines.
I tried with grep -n 'pattern' from the first file, which gives me:
21: pat
I would like to recursively list all files in a directory which match a given input pattern using ls. (Oh, and this is in Bash).
The only way I can think of to do this using ls is to shopt -s extglob and then use the ls --ignore=pattern option with the extended glob negate pattern !( pattern-list ).
Input file1 is:
-----
dog 123 4335
cat 13123 23424
deer 2131 213132
bear 2313 21313
I give the match the pattern from in other file ( like dog 123 4335 from file2).
I match the pattern of the line is dog 123 4335 and after print
all lines without match line my output is:
file1 :
cat 13123 23424
deer 2131 213132
bear 2313 21313
If only use without address of line only use the pa
In a bash script using sed how can I remove a block of lines beginning with -pattern a- and ending with -pattern b- where the the contents contains -pattern c- ( or does NOT contain -pattern c-)?
So :
line 1 -pattern a-
line 2
line 3 -pattern b-
line 4 -pattern a-
line 5 -pattern c-
line 6 -pattern b-
In this example I want to remove lines 4,5 and 6 (or remove 1,2 and 3 for not cont
Hi friends,
I am looking for sed command/script that would search for a given fixed pattern on odd lines and then if it matches, prints the matching pattern and the next line.
Pipe binary file matches grep results to file
I am using grep to match a pattern, but the output is strange.
Code:
$ grep -r -o "pattern" *
Gives me:
Code:
Binary file foo1 matches
Binary file foo2 matches
Binary file foo3 matches
To find the lines before/after, I then have to use the following on each file:
Code:
$ strings foo1 | grep -A1 -B1 "pattern"
Ho
What I try to accomplish with 'sed' is to remove a line if the pattern match.
and adding a line if pattern doesn't match.
But how could I make this?
Thanks in advance
Example:
I want this to use this line in Crontab:
*/1 * * * * script 1 test
With a other script I want to remove this line if this pattern is there, and otherwise, if pattern is not matching then add this line.
Hi
I know sed and awk has options to give range of line numbers, but
I need to replace pattern in specific lines
Something like
sed -e '1s,14s,26s/pattern/new pattern/' file name
Can somebody help me in this....
I am fine with see/awk/perl
Thank you in advance
I need to remove lines from a text file based on pattern but I need to keep the first n lines of that pattern.
Input
% 1
% 2
% 3
% 4
% 5
text1
text2
text3
output
%1
%2
text1
text2
text3
I used sed /^%/d file but it deletes all the lines starting with %, sed 3,/^%/d doesn't help either. I need to keep first n lines of the pattern and delete the rest