Ask a Question related to Linux / Unix Administration, Design and Development.
-
yaniv #1
Need help with parser unix script
Hi all,
I am looking for a unix command/script that would return line i+1
according to String in line i.
I mean, if i found a string XXX in line 3 then return line 4 and so
on.
Any help would be apperciated,
-- Valiky
yaniv Guest
-
#39098 [NEW]: parser bug: dash after if condition makes script crash without any error
From: michael dot axt at mindcox dot com Operating system: Linux x86-64Bit PHP version: 5.1.6 PHP Bug Type: Scripting Engine... -
unix and Windows php script compatibility
I'm a php novice and am developing a shopping cart application for a client who is hosted on a unix server. The hosting service requires that each... -
Simple Unix Shell Script
Hi, I am trying to execute a simple shell script to set the environment variables. It runs fine without any errors but i doesn't sets the... -
question on a unix script
Yes you are. cron is run with a different environment than exists in your shell. You must never assume that any command is in the path nor can... -
Unix alias command in script file
Le 29/05/03 3:19, dans 0001HW.BAFAD84400017877F0305600@news.earthlink.net, « Dave Reiser » <dbreiser@earthlink.net> a écrit : Yet another option... -
Andy Hibbins #2
Re: Need help with parser unix script
yaniv wrote:
The gnu grep command may be what you need:> Hi all,
>
> I am looking for a unix command/script that would return line i+1
> according to String in line i.
> I mean, if i found a string XXX in line 3 then return line 4 and so
> on.
grep -A 1 XXX /etc/afilename | grep -v XXX
where XXX is the string to search
and /etc/afilename is the filename to search.
say if /etc/afilename contained the following:
XXXdf
1
XXXfe
2
XXXge
3
XXXht
4
Output of the command would be:
1
2
3
4
Andy Hibbins Guest
-
Dave Hinz #3
Re: Need help with parser unix script
On 16 May 2004 04:28:52 -0700, yaniv <valiky@hotmail.com> wrote:
When is your homework due? What have you tried so far? Show what> Hi all,
>
> I am looking for a unix command/script that would return line i+1
> according to String in line i.
> I mean, if i found a string XXX in line 3 then return line 4 and so
> on.
you've done & where you're stuck, or describe your approach...something.
Dave Hinz Guest
-
yaniv #4
Re: Need help with parser unix script
It's not HW...
Basically i am looking to go over /etc/vfstab, which contains lines of
the following form:
# <Description>
/dev/dsk/... /home/bill ....
I want to print the device line in case i found a special string in
the description line right above.
So far I've tried:
1) sed
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
But i couldn't get rid of the description line in the output
2) grep -A1
but in case multiple lines matched, it returns the devices lines
seperated with --, which is quite annoying
help please...
tnx,
valiky
yaniv Guest
-
Chris F.A. Johnson #5
Re: Need help with parser unix script
On 2004-05-16, yaniv wrote:
sed -n '/regexp/{n;p;}'> It's not HW...
>
> Basically i am looking to go over /etc/vfstab, which contains lines of
> the following form:
>
> # <Description>
> /dev/dsk/... /home/bill ....
>
> I want to print the device line in case i found a special string in
> the description line right above.
>
> So far I've tried:
> 1) sed
> sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
> But i couldn't get rid of the description line in the output
--> 2) grep -A1
> but in case multiple lines matched, it returns the devices lines
> seperated with --, which is quite annoying
Chris F.A. Johnson [url]http://cfaj.freeshell.org/shell[/url]
================================================== =================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Chris F.A. Johnson Guest
-
Rovall #6
Re: Need help with parser unix script
Andy Hibbins wrote:
Not exactly. If you have a text like:> yaniv wrote:
>>>> Hi all,
>>
>> I am looking for a unix command/script that would return line i+1
>> according to String in line i.
>> I mean, if i found a string XXX in line 3 then return line 4 and so
>> on.
> The gnu grep command may be what you need:
>
> grep -A 1 XXX /etc/afilename | grep -v XXX
>
> where XXX is the string to search
> and /etc/afilename is the filename to search.
>
> say if /etc/afilename contained the following:
>
> XXXdf
> 1
> XXXfe
> 2
> XXXge
> 3
> XXXht
> 4
>
> Output of the command would be:
>
> 1
> 2
> 3
> 4
# bill's homedir
/dev/dsk/... /home/bill ....
and then do
grep -A 1 bill /etc/afilename | grep -v bill
you'll have null output!
For this case (searching through comments), I'd suppose to use something
like this:
grep -A 1 XXX <file> | grep -v '^#' | grep -v '^--$'
Second grep to filter out comments, third to avoid -- lines.
Rovall Guest
-
James T. Dennis #7
Re: Need help with parser unix script
yaniv <valiky@hotmail.com> wrote:
> Hi all,> I am looking for a unix command/script that would return line i+1
> according to String in line i.
> I mean, if i found a string XXX in line 3 then return line 4 and so
> on.#!/bin/sh> Any help would be apperciated,
> -- Valiky
while read line; do
case "$line" in
*XXX*) read line; echo "$line";;
esac
done
Just call that in a pipeline or with input redirection. This one just
uses shell built-ins and should work for any Bourne compatible shell. It
shouldn't need any bash or Korn extensions.
--
Jim Dennis,
Starshine: Signed, Sealed, Delivered
James T. Dennis Guest
-
John W. Krahn #8
Re: Need help with parser unix script
yaniv wrote:
perl -ne'/XXX/&&print scalar<>' yourfile>
> I am looking for a unix command/script that would return line i+1
> according to String in line i.
> I mean, if i found a string XXX in line 3 then return line 4 and so
> on.
John
--
use Perl;
program
fulfillment
John W. Krahn Guest



Reply With Quote

