Re: question in using cat/more in shell script
From: John W. Krahn (someone_at_example.com)
Date: 08/28/04
- Next message: Robert Bonomi: "Re: question in using cat/more in shell script"
- Previous message: Nasir: "some scripts & Question"
- In reply to: Gladiator: "question in using cat/more in shell script"
- Next in thread: Robert Bonomi: "Re: question in using cat/more in shell script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 28 Aug 2004 09:41:08 GMT
Gladiator wrote:
> Hi: I am trying to access a particular line in
> a text file using a script. The idea is to write
> out a specified line (after a certain ID has been
> identified) to another file. Here is what I wrote:
>
> ===============================
> #!/bin/csh
>
> # ========= set file name ==========
> set filename = data.dat
>
> # ======= set identifier ===========
> set id = ABC
>
> # ======== find line number of identifier =======
> set linenum = ` cat -n $filename | grep $id `
>
> # ======== the line to write out is 4 lines below identifier ======
> @ dispnum = $linenum[1] + 4
>
> # ======= more the line 4 lines below identifier ========
> more -1 +$dispnum $filename > outfile.dat
Will this do what you want?
grep -A 4 $id $filename | tail -1 > outfile.dat
John
-- use Perl; program fulfillment
- Next message: Robert Bonomi: "Re: question in using cat/more in shell script"
- Previous message: Nasir: "some scripts & Question"
- In reply to: Gladiator: "question in using cat/more in shell script"
- Next in thread: Robert Bonomi: "Re: question in using cat/more in shell script"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|