0

I am trying to remove all characters after particular match pattern i.e nfin to the end of line.

sample_text

xxsac00mi126 vddai:f1042 tkeept_iph xsac00.f1040 vdda lvtpfet m=1 nf=1 nfin=2 pdej=1.6e-07 asej=3.2e-16 lrsd=4e-08 pre_layout_local=0 

Command

sed -i "s/nfin\=[0-9].*//g" sample_text

Desired Output

xxsac00mi126 vddai:f1042 tkeept_iph xsac00.f1040 vdda lvtpfet m=1 nf=1 nfin=2  
4

Try this sed instead:

sed -E 's/ pdej.*$//'

Example:

sed -E 's/ pdej.*$//' file.txt 
xxsac00mi126 vddai:f1042 tkeept_iph xsac00.f1040 vdda lvtpfet m=1 nf=1 nfin=2

Where file.txt contains:

cat file.txt 
xxsac00mi126 vddai:f1042 tkeept_iph xsac00.f1040 vdda lvtpfet m=1 nf=1 nfin=2 pdej=1.6e-07 asej=3.2e-16 lrsd=4e-08 pre_layout_local=0


OR:
If you want (need) to use nfin as an anchor of sorts, use:

sed -E 's/(.*nfin=[0-9]).*/\1/' file.txt 
xxsac00mi126 vddai:f1042 tkeept_iph xsac00.f1040 vdda lvtpfet m=1 nf=1 nfin=2
  • I was looking for nfin as anchor mainly. The above command works fine ; can I use inline argument ? – JigarGandhi Feb 15 '17 at 8:19
  • If you want to match the last "nfin" use (.*nfin=...) -- if you want to match the first "nfin", omit the leading .* -> (nfin=...) – glenn jackman Feb 16 '17 at 14:43
1
sed -ne 's/[ ]nfin=[^ ]*/&\n/;P' < your_spice_netlist

But you have to keep in mind that spice netlists can have instances('x') or for that matter any element cross line boundaries and in such a scenario the above sed code might not work as maybe the nfin parameter might lie at the beginning of a line, like as, +nfin=23. Also, sometimes 'nfin' might appear parameterized, e.g., nfin='width*0.5 + 1./nfac*len', whereby the nfin=[0-9] will not match.

However if you can assure that there are no multilines (at least for instances) then the above should work reliably. Also there be no TABs.

0
sed -i "/nfin=[0-9]/{s//&\n/;P;d;}" sample_text

will remove the rest of line after nfin=[0-9]
For line(s) with nfin=[0-9]:

  • put \newline after the pattern (&)
  • Print line before \newline
  • delete line (print any more)
  • 1
    Could you please explain a bit, why your answer solves the problem? This is a knowledge base, so other users might benefit from it. – countermode Feb 15 '17 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.