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.
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
Hi All,
i'm writing a script where i have to grep for a pattern and the 3 lines after the pattern and comment them out.
Note that i have to do this for multiple files, i am able to grep the pattern and the next 3 lines but since solaris does not recognize the -i option, i was wondering if there was any workaround.
Hi
Im trying to do the following in sed. I want to delete any blank line at the start of a file until it matches a pattern and then stops.
Here Is a problem I am facing with awk.
Query --> I want to search for a string in a file and print next 15 lines below the matched string.
1.We do not have GNU grep so cannot use grep -A or grep -B commands.
2. Instead of passing the search pattern as a string to awk.
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
i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made.
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
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