Sponsored Content
Top Forums Shell Programming and Scripting search and retrieve previous line in file Post 302108135 by anbu23 on Friday 23rd of February 2007 07:04:31 AM
Old 02-23-2007
Quote:
I'm trying to write a SHELL (ksh) script that'll search the file say e.g filename = /filesysname1 grouped under FSstatus and get everthing beneath FSstatus group.
If all the groups are separated by blank line you can use this
Code:
awk -v RS="" -v FS="\n" -v ORS="\n\n" ' $1 ~ "FSstatus" && $0 ~ "/filesysname1" ' file

Quote:
Thus, I should be able search for anygroup, i.e. lines that start with an # and everything below it until the first blank line. I also need to know the group name, i.e. either FSstatus or FSgroup
If all the groups are separated by blank line you can use this to display group with group name "FSstatus"
Code:
awk -v RS="" -v FS="\n" -v ORS="\n\n" ' $1 ~ "FSstatus" ' file

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to retrieve a particular line from a file

Hi, I want to retrieve a particular line from a file and print its content to a file. Can you suggest how to do it in UNIX ?. Rgds vinayap (2 Replies)
Discussion started by: vinayap
2 Replies

2. Shell Programming and Scripting

Search text from a file and print text and one previous line too

Hi, Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11 Thanks for your help. (6 Replies)
Discussion started by: kamranjalal
6 Replies

3. Shell Programming and Scripting

How to use sed to search for string and Print previous two lines and current line

Hello, Can anybody help me to correct my sed syntax to find the string and print previous two lines and current line and next one line. i am using string as "testing" netstat -v | sed -n -e '/test/{x;2!p;g;$!N;p;D;}' -e h i am able to get the previous line current line next line but... (1 Reply)
Discussion started by: nmadhuhb
1 Replies

4. Shell Programming and Scripting

Append specific lines to a previous line based on sequential search criteria

I'll try explain this as best I can. Let me know if it is not clear. I have large text files that contain data as such: 143593502 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:11 N line 1 test line 2 test line 3 test 143593503 09-08-20 09:02:13... (3 Replies)
Discussion started by: jesse
3 Replies

5. Shell Programming and Scripting

solved -gawk, search for pattern - mark the previous line as a variable?

Im trying to parse ifconfig with awk and setup a bunch of variables in one shot. But Im having trouble figuring out how to work with data in previous lines. ifconfig output: eth0 Link encap:Ethernet HWaddr 00:50:DA:10:7F:1B inet addr:10.10.10.10 Bcast:10.10.10.127 ... (0 Replies)
Discussion started by: trey85stang
0 Replies

6. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

7. Shell Programming and Scripting

Retrieve logs for previous 4 hours

Hi, I am in the process of configuring a script, and i intend it to retrieve logs for previous four hours, and then scan for predefined errors. I am kind of stuck on the log retrieval part where the script will run early morning like 1 AM or 2 AM, the command as posted below will give me... (4 Replies)
Discussion started by: john_prince
4 Replies

8. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

9. Shell Programming and Scripting

Adding line in a file using info from previous line

I have a shell script that looks something like the following: mysql -uroot db1 < db1.sql mysql -uroot db2 < db2.sql mysql -uroot db3 < db3.sql mysql -uroot db4 < db4.sql .... different db names in more than 160 lines. I want to run this script with nohup and have a status later. So,... (6 Replies)
Discussion started by: MKH
6 Replies

10. UNIX for Beginners Questions & Answers

How to search a text in file and retrieve required lines following it with UNIX command?

I have requirement to search for a text in the file and retrieve required lines that is user defined with unix command. Eg: Find the text UNIX in the below file and need to return Test 8 & Test 9 Test 1 Test 2 Test 3 Test 4 UNIX Test 5 Test 6 Test 7 Test 8 Test 9 Result can... (8 Replies)
Discussion started by: Arunkumarsak4
8 Replies
IMDB-TOOLS(1)						      General Commands Manual						     IMDB-TOOLS(1)

NAME
imdb-get -- Looks up IMDB data for a film. SYNOPSIS
imdb-get [options] [--imdb-id id] [-l id] [--search search string] [-s search string] [--filename filename] [-f filename] [-h ] [--help] DESCRIPTION
This manual page documents briefly the imdb-get command. imdb-get has three modes. It can be called with imdb ID and a set of details to print, in which case it will retrieve those details either from the cache or IMDB. Secondly, it can be called with a filename in which case it will look the file up in the cache (resolving symlinks as appropriate and checking for multiple disks from the same film) and if that fails it will use the filename to search IMDB. Alterna- tively it may be used with just a search string, which will always search IMDB. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. -h --help Print syntax and options. -l --imdb-id Specify IMDBID to use in queries. -s --search Specify search string to use in queries. -f --filename Specify filename. Will be used to form search queries if no ID or search string is specified. -i --id Print IMDB ID (default if nothing else is selected). -t --title Print film title. -g --genre Print film genres. --tag Print film tag line. -y --year Print film year. -c --cover Print cover art URI. -m --print-filename Print film genres. -a --all Print all film details. -e --cachedir Set cache directory. -d --download-cover Download cover art locally. -r --refresh Force an update from IMDB not the cache. -n --rename Rename file based on IMDB title. -u --update-filename Update the filename in a stored record --prune-duplicates Removes cache files with duplicate filename entries. (Removes all but the most recently modified cache file) --refresh-cache Refresh all the details in the cache from IMDB (may be slow). FILES
Config options are read from /etc/imdbgetrc or $HOME/.imdbgetrc SEE ALSO
imdb(1) imdb-rename(1) imdb-link(1) imdb-update-cache(1) imdbgetrc(5) imdb-fxd(1) AUTHOR
This manual page was written by Matthew Johnson <debian@matthew.ath.cx>. Permission is granted to copy, distribute and/or modify this docu- ment under the terms of the GNU General Public License, Version 2 as published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL-2. IMDB-TOOLS(1)
All times are GMT -4. The time now is 03:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy