Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[b]Delete Items in a file.[/b] 2

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
How do I delete the last eight digits of each line?

Here is a sample of what needs to be deleted:

L258A:lp=L258:sd=LXXXK.S11:qt=text:00001000
L258B:lp=L258:sd=LXXXK.S11:qt=raw:00002000
L629A:lp=L629:sd=LXXXK.S11:qt=text:00003000
L629B:lp=L629:sd=LXXXK.S11:qt=raw:00004000
D206:rm=WXXBQ9Q2:rp=P11111PLD19L206DRAFT$:qt=auto:qg=107:00005000
D208:rm=WXXBQ9Q2:rp=P11111PLD19L208DRAFT$:qt=auto:qg=107:00006000
D210:rm=WXXBQ9Q2:rp=P11111PLD19L210DRAFT$:qt=auto:qg=107:00007000
D254:rm=NXXQ9QG:rp=P11111PLD19L254DRAFT$:qt=auto:qg=143:00008000
D255:rm=NXXQ9QG:rp=P11111PLD19L255DRAFT$:qt=auto:qg=143:00009000
D257:rm=NXXXQQG:rp=P11111PLD19L257DRAFT$:qt=auto:qg=143:00011000
.. --- gap in data ------------------------------------------------
C783:rm=WXSBQ9QF:rp=P11111PLD19L783$:qt=auto:qg=139:00065000
C545:rm=WXSBQ9Q6:rp=P11111PLD19L545$:qt=auto:qg=133:00066000
C546:rm=WXSBQ9Q6:rp=P11111PLD19L546$:qt=auto:qg=133:00067000
C547:rm=WXSBQ9Q6:rp=P11111PLD19L547$:qt=addd:qg=133:00068000
C548:rm=WXSBQ9Q6:rp=P11111PLD19L548$:qt=asss:qg=133:00069000
C256:rm=WXSBTQ75:rp=P11111PLD19L256$:qt=auto:qg=208:
P221A:lp=P221:sd=L003K.111:qt=text:00071000
P221B:lp=P221:sd=L003K.111:qt=raw:00072000
P301A:lp=P301:sd=L003K.111:qt=text:00073000
P301B:lp=P301:sd=L003K.111:qt=raw:00074000
TRRR:rm=AUxxxbM:rp=TRMS:cl=|writer=%f|jobn=%j:qt=cctl:00075000



The last 8 digits need to be deleted. There may be a line after the colon :)) that doesn't have any digits so I may need to keep an eye out for those.

Any ideas on what the script will look like?

Is there a way for me to ask within the script.

Run the script.
Then you are prompted to enter the file that needs to be trimmed?

File is entered and the script is run against it and produces a different ouput file.

Thanks for any help that can be given.

 
How do I delete the last eight digits of each line?
sed 's![0-9]\{8\}$!!' /path/to/input >output

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
nawk 'BEGIN {FS=OFS=":"} {$NF="";print}' myFile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Vlad:

I understand what you're doing with the input and output field separators, but I don't understand what you are doing with the number of fields, $NF, syntax.

Please, explain?

Regards,


Ed
 
olded,
$NF=""
change last field value by empty string
NF is the number of fields in the current record, so $NF is the last field (as $1 is the first).

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
thanks, PHV! [wink]

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top