![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl how to move pointer to previous line in a txt file? | tqlam | Shell Programming and Scripting | 5 | 01-27-2008 05:24 PM |
| How to retrieve a particular line from a file | vinayap | UNIX for Dummies Questions & Answers | 2 | 07-11-2007 02:16 PM |
| how do we retrieve a line from a file in unix | lmadhuri | Shell Programming and Scripting | 2 | 02-07-2007 08:07 AM |
| (cont) Retrieve line from a file based on a value in specific column | efernandes | UNIX for Dummies Questions & Answers | 0 | 01-27-2007 01:00 PM |
| Retrieve line from a file based on a value in specific column | efernandes | UNIX for Dummies Questions & Answers | 1 | 01-27-2007 11:04 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
search and retrieve previous line in file
I've got a file with the following layout:
#STMP FSgroup filename /filesysname1 filestatus 2 #STMP FSstatus filename /filesysname1 ratio 30 #STMP FSgroup filename /filesysname1 filestatus 2 #STMP FSstatus filename /filesysname6 ratio 60 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. 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 Look really difficult for me, any help out there tks William ![]() |
|
||||
|
Will this be ok?
Code:
var=filesysname1
awk -F" " 'BEGIN{group=""; x=0} { if( x == 1 ) { print } if( $0 ~ /^#/) { group = $0; next } if( $0 ~ /'$var'/ ) { x=1; print group; print $0} else { x = 0 } }' file
|
|
||||
|
Quote:
Code:
awk -v RS="" -v FS="\n" -v ORS="\n\n" ' $1 ~ "FSstatus" && $0 ~ "/filesysname1" ' file Quote:
Code:
awk -v RS="" -v FS="\n" -v ORS="\n\n" ' $1 ~ "FSstatus" ' file |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|