1

I have a big file name lef_list with data in below format:

$PRJ/fp/t/std/tcb/libs/tcb.lb.gz \ $PRJ/mm/T/v/mem_gen/ram/NLDM/ram.lib \ 

I want to read each line of file and split the lines into two based on pattern '/libs/' or '/NLDM/' in line and replace those with word '/LEF/' and write in a new file.

The output should be like :

$PRJ/fp/t/std/tcb/lef/tcb.lb.gz \ $PRJ/mm/T/v/mem_gen/ram/LEF/ram.lib \ 

I tried the below code:

while IFS="/libs/" read -r line val do echo "$line"/LEF/"$val"; done < lef_list 

This code shows error as while expression syntax. command not found.

Someone please suggest any solution.

1 Answer 1

1

A simple sed should do the job:

sed -E 's~/(libs|NLDM)/~/LEF/~g' file $PRJ_WORK_DIR/foundationip/tsmc/tsmc_lvt_stdcells/tcbn16ffcllbwp16p90cpdlvt/LEF/ccs/tcbn16ffcllbwp16p90cpdlvtssgnp0p72vm40c_hm_ccs.lib.gz \ $PRJ_WORK_DIR/mem/tech/TSMC_16FFC/v37/mem_gen/data_new/ram_dp_ulvt_pg_rd_64x44_mux4/LEF/ram_dp_ulvt_pg_rd_64x44_mux4_ssgnp0p72vm40c.lib \ 

Pattern /(libs|NLDM)/ matches /libs/ or /NLDM/ and replaces that with /LEF/.

Or if you have to use awk only then:

awk '{gsub(/\/(libs|NLDM)\//, "/LEF/")} 1' file 
Sign up to request clarification or add additional context in comments.

5 Comments

If I want to replace based on pattern in line, like if mem_gen in line, I want to replace /NLDM/ with /LEF/ and rest with /lef/?
@NEHACHOUDHARY: That would be: sed '/\/mem_gen\// s~/NLDM/~/LEF/~g; s~/libs/~/lef/~g' file
If I have a data, i want to search for mem_gen in line and if found replace /NLDM/ with /LEF/ and output only the first part of data till /LEF/
@NEHACHOUDHARY: Not a good idea to keep asking new questions from comments. I have answered one additional problem from comments but usually it is one problem per post on SO
Last problem's solution: sed -E '/\/mem_gen\// s~(.*)/NLDM/.*~\1/LEF/~g; s~(.*)/libs/.*~\1/lef/~g' file

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.