Re: file editing
From: Eric Pement (pemente_at_northpark.edu)
Date: 08/16/04
- Next message: swim learning: "Re: change those lines"
- Previous message: Billy N. Patton: "bash vs csh"
- In reply to: Joey: "file editing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Aug 2004 10:50:30 -0700
veshee@hotmail.com (Joey) wrote in message news:<fd9ccebb.0408160227.d98b922@posting.google.com>...
> i want to edit only the line beginig with a 'P' os 'S'
> the other must stay the same
>
> This result should be output to another file
>
> This is my attempt, the editing works fine , but i can get to print
> the rest f the lines in the file unchanged
>
> -------------
[ ... deletion ... ]
> awk '/^P/ {
> rem1=NR % 2
> id=substr($0,1,1);
> sequence=substr($0,2,4);
> name=substr($0,6,33);
> house=substr($0,39,38);
> street=substr($0,77,4);
> cycle=substr($0,81,2);
> walk=substr($0,83,3);
> read=substr($0,86,63);
> filler=substr($0,149,42);
> period=substr($0,191,2);
> time=substr($0,193,2);
> if (rem1 == 0)
> {
> printf("%s%sMR A CUSTOMER %s%s%s%s%s%s%s%s\n",id,
> sequence, house, street, cycle, walk, read, filler, period, time);
> }
> else
> {
> printf("%s%sMRS A DCD %s%s%s%s%s%s%s%s\n",id,
> sequence, house, street, cycle, walk, read, filler, period, time);
> }
> }' $IN_FILE
> #
>
> -------------
> Thanks in advance
Your task would have been easier had you learned about the FIELDWIDTHS
variable. Maybe you don't have access to gawk. At any rate, the
solution is to simply address the other, nonmatching lines of the
file:
awk '/^P/ { # print lines that begin with P
... your script here ...
}
/^[^P]/ # print lines that begin with non-P
/^$/ # print blank lines also (optional)
' $IN_FILE
By specifying a "/pattern/" with no "{action}", the default action is
to print the lines that match the pattern. You also have the option of
printing or omitting blank lines from the output.
-- Eric Pement
- Next message: swim learning: "Re: change those lines"
- Previous message: Billy N. Patton: "bash vs csh"
- In reply to: Joey: "file editing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|