Sponsored Content
Top Forums Shell Programming and Scripting Print lines between two strings multiple occurencies (with sed, awk, or grep) Post 302595279 by theclem35 on Thursday 2nd of February 2012 02:22:07 PM
Old 02-02-2012
Thanks a lot!
How can I add a string after each block ?
I tried sed -ne '/debut_sect/,/fin_sect/{/debut_sect\|fin_sect/d;p}' -ne '$a\\n---- END OF BLOCK ------\n' infile

But it add ---- END OF BLOCK ------ only one time, at the end of the file !
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print only lines in between two strings using awk

Hi, I want to print only lines in between two strings and not the strings using awk. Eg: OUTPUT top 2 bottom 1 left 0 right 0 page 66 END I want to print into a new file only top 2 bottom 1 left 0... (4 Replies)
Discussion started by: jisha
4 Replies

2. UNIX for Dummies Questions & Answers

print multiple lines with awk

Hi everyone! I'm not new to Unix, but I've never used awk before. I tried to look up this information on several sites and forums, I also looked in the documentation but I haven't found a solution yet. I would like to print the previous 3 lines before and the following 4 lines after the... (6 Replies)
Discussion started by: djcsabus
6 Replies

3. Shell Programming and Scripting

How to get lines started with matched strings using sed or grep for loop?

I have a huge file and want to separate it into several subsets. The file looks like: C1 C2 C3 C4 ... (variable names) 1 .... 2 .... 3 .... : 22 .... 23 .... I want to separate the huge file using the column 1, which has numbers from 1 to 23 (but there are different amount of... (8 Replies)
Discussion started by: AMBER
8 Replies

4. Shell Programming and Scripting

print multiple lines using the grep command.

Hi All, Please find my piece of code below. I am trying to grep the word SUCCESS from $LOGFILE and storing in the grepvar variable. And i am placing that variable in a file. Now if i open the file, i can see the four lines but not in seperate four line s but in a paragraph. If am mailing that log... (8 Replies)
Discussion started by: intiraju
8 Replies

5. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

6. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

7. Shell Programming and Scripting

Sed or Awk for lines between two strings multiple times and keep the last one

Hi, I am trying to get lines between the last occurrences of two patterns. I have files that have several occurrences of “Standard” and “Visual”. I will like to get the lines between “Standard” and “Visual” but I only want to retain only the last one e.g. Standard Some words Some words Some... (4 Replies)
Discussion started by: damanidada
4 Replies

8. Shell Programming and Scripting

How to print the lines between the pattern using awk/grep/sed?

Hi, I need a help to search a pattern and print the multiple lines between them. Input file: Tue May 29 12:30:33 EDT 2012:threadWebContainer : 357:com.travimp.hotelierlinks.abba.service.RequestHandler.requestService(String, ITICSDataSet): hotelCancelReservation request: ... (4 Replies)
Discussion started by: aroragaurav.84
4 Replies

9. UNIX for Beginners Questions & Answers

How to find=grep or maybe sed/awk for multiple lines of text?

Hi, I am running the following: PASS="username/password" sqlplus -s << EOF | grep -v "^$" $PASS set feedback off set heading off set termout off select name from v\$database ; exit EOF Which gives ERROR: ORA-28002: the password will expire within 5 days PSMP1 (1 Reply)
Discussion started by: newbie_01
1 Replies

10. Shell Programming and Scripting

awk or sed or grep filter a line and/or between strings

Hi, I have multiple files on a directory with the following content: blahblah blahblah hostname server1 blahblah blahblah ---BEGIN--- aaa bbb ccc ddd ---END--- blahblah blahblah blahblah I would like to filter all the files with awk or sed or something else so I can get below... (6 Replies)
Discussion started by: bayupw
6 Replies
grep(1) 						      General Commands Manual							   grep(1)

NAME
grep, egrep, fgrep - search a file for a pattern SYNOPSIS
Plain call with pattern pattern [file ...] Call with (multiple) -e pattern pattern] ... [file ...] Call with -f file pattern_file] [file ...] Obsolescent: [expression] [file ...] [strings] [file ...] DESCRIPTION
The command searches the input text files (standard input default) for lines matching a pattern. Normally, each line found is copied to the standard output. supports the Basic Regular Expression syntax (see regexp(5)). The option supports Extended Regular Expression (ERE) syntax (see regexp(5)). The option searches for fixed strings using the fast Boyer-Moore string searching algorithm. The and options treat newlines embedded in the pattern as alternation characters. A null expression or string matches every line. The forms and are maintained for backward compatibility. The use of the and options is recommended for portability. Options Extended regular expressions. Each pattern specified is a sequence of one or more EREs. The EREs can be separated by newline characters or given in separate expression options. A pattern matches an input line if any ERE in the sequence matches the contents of the input line without its trailing newline character. The same functionality is obtained by using Fixed strings. Each pattern specified is a sequence of one or more strings. Strings can be separated by newline characters or given in separate expression options. A pattern matches an input line if the line contains any of the strings in the sequence. The same functionality is obtained by using Each line is preceded by the block number on which it was found. This is useful in locating disk block numbers by context. Block numbers are calculated by dividing by 512 the number of bytes that have been read from the file and rounding down the result. Only a count of matching lines is printed. Same as a simple expression argument, but useful when the expression begins with a hyphen Multiple options can be used to specify multiple patterns; an input line is selected if it matches any of the specified patterns. The regular expression and or strings list is taken from the pattern_file. Suppress printing of filenames when searching multiple files. Ignore uppercase/lowercase distinctions during comparisons. Only the names of files with matching lines are listed (once), separated by newlines. If standard input is searched, a path name of will be written, in the POSIX locale. In other locales, may be replaced by something more appropriate in those locales. Each line is preceded by its relative line number in the file starting at 1. The line number is reset for each file searched. This option is ignored if or is specified. (Quiet) Do not write anything to the standard output, regardless of matching lines. Exit with zero status upon finding the first matching line. Overrides any options that would produce output. Error messages produced for nonexistent or unreadable files are suppressed. All lines but those matching are printed. Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or pre- ceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore. (eXact) Matches are recognized only when the entire input line matches the fixed string or regular expression. The file name is output in all the cases in which output is generated if there are more than one input file, unless the -h option is speci- fied. Care should be taken when using the characters and in expression, because they are also meaningful to the shell. It is safest to enclose the entire expression argument in single quotes EXTERNAL INFLUENCES
Environment Variables determines the locale to use for the locale categories when both and the corresponding environment variable (beginning with do not specify a locale. If is not specified or is set to the empty string, a default of (see lang(5)) is used. determines the locale to use to override any values for locale categories specified by the settings of or any environment variables begin- ning with determines the collating sequence used in evaluating regular expressions. determines the interpretation of text as single byte and/or multi-byte characters, the classification of characters as letters, the case information for the option, and the characters matched by character class expressions in regular expressions. determines the language in which messages are displayed. If any internationalization variable contains an invalid setting, the commands behave as if all internationalization variables are set to See environ(5). International Code Set Support Single-byte and multi-byte character code sets are supported. RETURN VALUE
Upon completion, returns one of the following values: One or more matches found. No match found. Syntax error or inaccessible file (even if matches were found). EXAMPLES
In the POSIX shell (sh(1)) the following example searches two files, finding all lines containing occurrences of any of four strings: Note that the single quotes are necessary to tell when the strings have ended and the file names have begun. For the C shell (see csh(1)) the following command can be used: To search a file named containing the following entries: the command: prints: To search a file for lines that contain either a or use either of the following commands: Search all files in the current directory for the string Search all files in the current directory subtree for the string and ensure that no error occurs due to file name expansion exceeding sys- tem argument list limits: The previous example does not print the name of files where string appears. To force to print file names, add a second argument to the command portion of the command line: In this form, the first file name is that produced by and the second file name is the null file. WARNINGS
(XPG4 only.) If the option is specified, the exit status will be zero if an input line is selected, even if an error was detected. Other- wise, default actions will be performed. If the option is specified with non-word constituent characters, then the output is unexpected. SEE ALSO
sed(1), sh(1), regcomp(3C), environ(5), lang(5), regexp(5). STANDARDS CONFORMANCE
grep(1)
All times are GMT -4. The time now is 08:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy