I want to edit the file contents in the 2nd line and 2nd column ,which is a file name from that I want to remove the part after the last underscore and before the file extension .

The contents of the file looks like below Input file contents

01 |com_101_00000_0001_a234.txt|100

expected output file content

01 |com_101_00000_0001.txt|100

The number of underscores may vary depending upon the file names present inside the .ctl files. Also there are multiple files in a folder likes this ,i want to change the contents for all .ctl files in the 2nd line similarly.

Operating system details Linux  2.6.32 -696.30.1.e16

I tried with the below solution
cat com_101_00000_0001.ctl | sed 's/(.)_[^_](.[^_]*)$/\1\2/'

This edited the file contents but shows the contents in the putty console itself ,what i want is to modify the original files in a particular path in server

Please tell where it went wrong

  • what did you try? – pLumo Dec 7 '18 at 12:10
  • I tried this ,with the help of the forum and google i am a starter in unix but this doenst work it seems – Vinay Dec 7 '18 at 12:14
  • Please add this information to your question and tell us what went wrong. – pLumo Dec 7 '18 at 12:15
  • its added ,hope it helps – Vinay Dec 7 '18 at 12:24

This is the third time now you ask the nearly same question ( Qu.1, Qu.2, and this one ) - how about collecting the answers given and see how far you get?

Did you try this answer? Please read about redirection if you want the result captured in a file.

| improve this answer | |
  • Qu 2 and Qu3 are same as u said .Both deals with the file content editing,since i earlier wrongly described the requirement i asked as a fresh question(i'm new to the forum) . Qu 1 is regarding renaming the files. Qu3 now asked as an extension to that .hope it will be helpful for other beginners like me – Vinay Dec 7 '18 at 13:08

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