Re: question in using cat/more in shell script

From: John W. Krahn (someone_at_example.com)
Date: 08/28/04


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


Relevant Pages

  • Re: Stupid question: what does += do?
    ... The script I am looking at has ... depending on the implementation. ... use Perl; ...
    (comp.unix.shell)
  • Re: space in variabile
    ... > I have a problem in a script with a for cicle. ... use Perl; ...
    (comp.unix.shell)
  • Re: awk command
    ... i am working on script. ... I have to use awk command and only get the MAR 21 to be displayed in ... You can do it in Perl: ...
    (comp.unix.programmer)
  • Re: modifying files using script
    ... specific string with another one. ... This script works well for one file but exits after that. ... use Perl; ...
    (comp.unix.shell)
  • 2005-11-20 [de.comp.lang.perl.cgi] FAQ
    ... Programmiersprache Perl in CGI-Scripten. ... Wo gibt es Dokumentation über Perl und CGI? ... Hilfe zum Programm perldoc kann man mit 'perldoc perldoc' ... Mein Script läuft nicht bei meinem Provider. ...
    (de.comp.lang.perl.cgi)