Sponsored Content
Top Forums Shell Programming and Scripting search string in a file and retrieve 10 lines including string line Post 302445937 by ranjithpr on Tuesday 17th of August 2010 08:01:01 AM
Old 08-17-2010
Solution using awk

Code:
$ cat 1.txt
word1 line1 word2
word1 line2 word2
word1 line3 word2
word1 line4 word2
word1 line5 word2
word1 line6 word2
word1 line7 word2
word1 line5 word2
word1 line8 word2
word1 line9 word2

$ awk '/line5/ {for(i=0;i<4;i++) {print;if(!getline) exit;} }' 1.txt
word1 line5 word2
word1 line6 word2
word1 line7 word2
word1 line5 word2

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retrieve string from each line in a file based on a pattern in Unix

I have a file which contains several lines. Sample content of the file is as below. OK testmessage email<test@123> NOK receivemessage email<123@test> NOK receivemessage email(123@test123) NOK receivemessage email<abc@test> i would like to know by scripting will... (10 Replies)
Discussion started by: ramasar
10 Replies

2. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

3. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

4. Shell Programming and Scripting

Search string and print the above line and below lines?.

if the first string matches then print the previous line and current line and also print the following lines if the other string search matches. Input ------ TranTime 2012 10 12 The Record starts here Accountnumber: 4632473431274 TxnCode 323 TranID 329473242834 ccsdkcnsdncskd... (7 Replies)
Discussion started by: laknar
7 Replies

5. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

6. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

7. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

8. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

9. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

10. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies
MAN.CONF(5)						      BSD File Formats Manual						       MAN.CONF(5)

NAME
man.conf -- configuration file for manual pages DESCRIPTION
The man.conf file contains the default configuration used by man(1), apropos(1), whatis(1), catman(8), and makewhatis(8) to find manual pages and information about manual pages (e.g. the whatis database). Manual pages are located by searching an ordered set of directories called the ``man path'' for a file that matches the name of the requested page. Each directory in the search path usually has a set of subdirectories in it (though this is not required). When subdirectories are used, there are normally two subdirectories for each section of the manual. One subdirectory contains formatted copies of that section's manual pages that can be directly displayed to a terminal, while the other section subdirectory contains unformatted copies of the pages (see nroff(1) and mdoc(7)). Formatted manual pages are normally named with a trailing ``.0'' suffix. The man.conf file contains comment and configuration lines. Comment lines start with the ``#'' character. Blank lines are also treated as comment lines. Configuration lines consist of a configuration keyword followed by a configuration string. There are two types of configura- tion keywords: control keywords and section keywords. Control keywords must start with the ``_'' character. The following control keywords are currently defined: _build identifies the set of suffixes used for manual pages that must be formatted for display and the command that should be used to for- mat them. Manual file names, regardless of their format, are expected to end in a ``.*'' pattern, i.e. a ``.'' followed by some suffix. The first field of a _build line contains a man page suffix specification. The suffix specification may contain the nor- mal shell globbing characters (NOT including curly braces (``{}'')). The rest of the _build line is a shell command line whose standard output is a formatted manual page that can be directly displayed to the user. There should be exactly one occurrence of the string ``%s'' in the shell command line, and it will be replaced by the name of the file which is being formatted. _crunch used by catman(8) to determine how to crunch formatted pages which originally were compressed man pages: The first field lists a suffix which indicates what kind of compression were used to compress the man page. The rest of the line must be a shell command line, used to compress the formatted pages. There should be exactly one occurrence of the string ``%s'' in the shell command line, and it will be replaced by the name of the output file. _default contains the system-wide default man path used to search for man pages. _subdir contains the list (in search order) of section subdirectories which will be searched in any man path directory named with a trail- ing slash (``/'') character. This list is also used, even if there is no trailing slash character, when a path is specified to the man(1) utility by the user, by the MANPATH environment variable, or by the -M and -m options. _suffix identifies the set of suffixes used for formatted man pages (the ``.0'' suffix is normally used here). Formatted man pages can be directly displayed to the user. Each suffix may contain the normal shell globbing characters (NOT including curly braces (``{}'')). _version contains the version of the configuration file. _whatdb defines the full pathname (not just a directory path) for a database to be used by the apropos(1) and whatis(1) commands. The pathname may contain the normal shell globbing characters, including curly braces (``{}''); to escape a shell globbing character, precede it with a backslash (``''). Section configuration lines in man.conf consist of a section keyword naming the section and a configuration string that defines the directory or subdirectory path that the section's manual pages are located in. The path may contain the normal shell globbing characters, including curly braces (``{}''); to escape a shell globbing character, precede it with a backslash (``''). Section keywords must not start with the ``_'' character. A section path may contain either a list of absolute directories or a list of or relative directories (but not both). Relative directory paths are treated as a list of subdirectories that are appended to the current man path directory being searched. Section configuration lines with absolute directory paths (starting with ``/'') completely replace the current man search path directory with their content. Section configuration lines with absolute directory paths ending with a trailing slash character are expected to contain subdirectories of manual pages, (see the keyword ``_subdir'' above). The ``_subdir'' subdirectory list is not applied to absolute section directories if there is no trailing slash. In addition to the above rules, the man(1) command also always checks in each directory that it searches for a subdirectory with the same name as the current machine type. If the machine-specific directory is found, it is also searched. This allows the manual to contain machine-specific man pages. Note that the machine subdirectory does not need to be specified in the man.conf file. Multiple specifications for all types of man.conf configuration lines are cumulative and the entries are used in the order listed in the file; multiple entries may be listed per line, as well. FILES
/etc/man.conf Standard manual configuration file. EXAMPLES
Given the following man.conf file: _version BSD.2 _subdir cat[123] _suffix .0 _build .[1-9] nroff -man %s _build .tbl tbl %s | nroff -man _default /usr/share/man/ sect3 /usr/share/man/{old/,}cat3 By default, the command ``man mktemp'' will search for ``mktemp.<any_digit>'' and ``mktemp.tbl'' in the directories ``/usr/share/man/cat1'', ``/usr/share/man/cat2'', and ``/usr/share/man/cat3''. If on a machine of type ``vax'', the subdirectory ``vax'' in each directory would be searched as well, before the directory was searched. If ``mktemp.tbl'' was found first, the command ``tbl <manual page> | nroff -man'' would be run to build a man page for display to the user. The command ``man sect3 mktemp'' would search the directories ``/usr/share/man/old/cat3'' and ``/usr/share/man/cat3'', in that order, for the mktemp manual page. If a subdirectory with the same name as the current machine type existed in any of them, it would be searched as well, before each of them were searched. SEE ALSO
apropos(1), machine(1), man(1), whatis(1), whereis(1), fnmatch(3), glob(3), catman(8), makewhatis(8) BSD
December 27, 2011 BSD
All times are GMT -4. The time now is 03:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy