how to cut a field of a line in a text file?

Hi,
I have text file which contains lines like :
a/a/a/a/.project
b/b/b/b/b/.project
c/c/c/.project
d/.project
e/e/e/e/.project

i want for all lines the last word .project should be removed and the file should look like :

a/a/a/a/
b/b/b/b/b/
c/c/c/
....

how to proceed ? Please help. Thanks in advance.

You can read the file line-by-line using xargs, replace the / by some other delimiter and then pass it to basename command for cutting the .project extension and then replace the delimiter in the output back to /

I tried it and it worked perfectly for me but need to make sure that the intermediate delimiter that you are using is not present anywhere else in the file or else that would also be converted to /

cud u please list out the commands u have used?

A combination of xargs, tr and basename. I do not want to give the whole command here since this question sounds like a homework question to me.

It is not a homework question . I am facing this problem for building an application as a continous integration activity and this file acts as a configuration file. Anyways thanks for giving the idea, trying to implement.

man dirname

thats nice :slight_smile:

cat filename | xargs -l1 echo | tr "/" "-" | xargs -l1 -i basename {} .project | tr "-" "/"
OR
cat filename | xargs -l1 dirname

would do what you expect