1

Consider the following input string.

PLOG_NFET_SLVT nf=3 ng=1 nl=20n

Output

PLOG_NFET_LVT nf=3 ng=1 nl=14n

Note: 1st and last word are replaced. Also in between data varies. So I can not have a constant pattern. I tried using below command.

sed -i 's/PLOG.*FET_SLVT.*nl=20n/PLOG.*FET_LVT.*nl=14n/g' file

and output is :

PLOG.*FET_LVT.*nl=14n

Any help?

  • What's the operation on the 20n to 14n? – slm Aug 2 '18 at 11:49
  • it's a fixed change. SLVT --> LVT and 20-->14 – Roopak Vasa Aug 2 '18 at 11:52
  • See my method, do 2 subs instead of one. – slm Aug 2 '18 at 11:53
1

You can use a capture group in the search pattern and add the backreference (\1 or \2) to the replace pattern:

sed 's/PLOG_\([A-Z]\)FET_SLVT \(.*\) nl=20n/PLOG_\1FET_LVT \2 nl=14n/'
1

Try this,

 sed -i 's/^PLOG_NFET_SLVT/PLOG_NFET_LVT/g;s/20n$/14n/g' file
  • search for the patter starts with PLOG_NFET_SLVT and replace with PLOG_NFET_LVT
  • and search for the patter ends with 20n and replace with 14n
0

Try this:

sed 's/SLVT/LVT/;s/20n/14n/'

Example

$ echo "PLOG_NFET_SLVT nf=3 ng=1 nl=20n" | sed 's/SLVT/LVT/;s/20n/14n/'
PLOG_NFET_LVT nf=3 ng=1 nl=14n
  • I guess these are two separate commands. But here I need both the substitutions on the same string. It's "AND" replacement. Thanks – Roopak Vasa Aug 2 '18 at 11:54
  • 1
    This is a AND replacement, it's done on 1 string. – slm Aug 2 '18 at 11:55
  • 1
    @RoopakVasa Every sed command is always applied to all lines (unless the commands branches to another part of a script or explicitly continues with the next line or quits). – Kusalananda Aug 2 '18 at 12:41
  • @slm OP's concern are genuine. Only those finfets whose model names equal "PLOG_NFET_SVT" and out if these, which have a channel length of 20nm should be shrinked to 14nm. What your sed code would do is much more than that. – Rakesh Sharma Aug 4 '18 at 6:56
  • @RakeshSharma - sigh...there are concerns wrt the regex, but easily addressed. The OP provides barely any sample data or requirements, this solves the issue and does not have any issues w/ doing too much or too little based on what he/she has shown. Instead of focusing on the ppl giving too general an A'er, you should be directing your critiques to the OP who isn't specifying his/her Q with enough data or requirements. – slm Aug 4 '18 at 13:04

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.