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
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 I am trying to use SED to replace the line matching a pattern using the command
sed 'pattern c\
new line
' <file1 >file 2
I got two questions
1. how do I insert a blank space at the beginning of new line?
2. how do I use this command to execute multiple command using the -e options (if possible)? as I want to replace multiple lines in a single file.
Thanks
Robert
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.
I have an MRTG configuration file containing some lines starting with the word "Target". Now in such lines there is a pattern starting with the character "#" and end with character ":".
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
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.
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
I have data that looks similar to this -
Quote:
John Smith (Address)
123 Main St
Unit 1
Los Angeles, CA 90201
Jane Smith (Address)
321 Elm St
Denver, CO 80201
So I need everything between each name, but I am not guaranteed that each time I match a name that I will have the same amount of lines, so I do a range pattern search line this to get all lines, no matte