remove part of a line

Hi
I need some help with using shell script to analyze the content of a file. I hope someone can help me.

I have a file with content like the following:
/foldera/database/procedure/a.proc$$/version1/2
/folderb/database/procedure/proj1/b.proc$$/version2/2

I need to write a shell script to get the lines that contains ".proc" but I need to delete anything after .proc.
For example, for the above two lines, I need to get
/foldera/database/procedure/a.proc
/folderb/database/procedure/proj1/b.proc

So that I can go to each file and perform more analysis

when I do

grep ".proc" file.txt

I get the entire line including $$...
I am not sure how to remove the $$.. part

Please help

Thanks

someone post the similar problem as mine.

It is to remove .null T from 'M000071.null T'
The script

echo 'M00071.null T' | sed 's#^\(M[0-9][0-9]*\)[.]null.*#\1#'

works

I try

echo '/foldera/database/procedure/a.proc@@/version1/2' | sed 's#^\(*\)[.]proc.*#\1#'

My script just return the whole line.

I can't figure out what's wrong with my script...
Thanks in advance for any help

Why don't you simply do this:

$ cat file.txt
/foldera/database/procedure/a.proc$$/version1/2
/folderb/database/procedure/proj1/b.proc$$/version2/2
$ cut -d'$' -f1 < file.txt
/foldera/database/procedure/a.proc
/folderb/database/procedure/proj1/b.proc

HTH

 cat file.txt | awk -F '\\$\\$' '{print $1}' 

And another one:

or:

Hi All
Thank you all for your help. I am using cut, because it's easier to understand for me

I have an issue with grep before pipe the result to get the $$.. removed.

I have
grep ".proc" file.txt | cut ....

From my understanding, it should only return lines with .proc
However, I am not getting how come the following line also gets returned?

/vobs/aw/database/proc/Account$$/main

Can someone help me, how can I modify my grep so that only something like a.proc or b.proc get returned ?

Thanks

sed -n -e "s/\$\$.*//p" input.txt

Hi Vino
I tried your code. However, it doesn't solve my grep problem.

Do you have any other solution?

Thanks

cat file | grep proc | awk -F"$" '{ print $1 }'

Hi All
I have just realized that beside removing anything after $$, I also need to remove anything before the file name.

That is, if my file has the following:
/foldera/database/procedure/a.proc$$/version1/2
/folderb/database/procedure/proj1/b.proc$$/version2/2

I hope to have the following result:
a.proc
b.proc

I have tried using unix "cut" command, but I am no where getting the result I wanted... could someone please give me some example...I am really stucked.

Thanks

That's because the "." stands for any character and grep matches it to the slash that comes before proc (/proc). To match "." escape it so that it loses its special meaning...

grep "\.proc" file.txt | cut

What is your grep problem ?

If your input is

/vobs/aw/database/proc/Account$$/main
/foldera/database/procedure/a.proc$$/version1/2
/folderb/database/procedure/proj1/b.proc$$/version2/2

then the expected output is

a.proc
b.proc

Right ?

Try this

sed -n -e "s/.*\/\([^\/]*\.proc\)\$\$.*/\1/p" input.txt

cat file | cut -d "$" -f1

Can u try this one out........

while read a
do
echo $a | awk -F"." '{print $1".proc"}'
done < filename

This looks simpler

sed -ne "s/\$\$.*//p" input.txt | xargs basename

An awk:

awk '/\.proc/{sub(/\$.*/,"",$0);print}' RS='/' file.txt

let
cat dot.txt
/foldera/database/procedure/a.proc$$/version1/2
/folderb/database/procedure/proj1/b.proc$$/version2/2
/folderb/database/procedure$$/proj1/version3/45
$
$ cat dot.txt | awk -F"." '/.proc\$\$/ {print $1".proc"}'
/foldera/database/procedure/a.proc
/folderb/database/procedure/proj1/b.proc