remove part of a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove part of a line
# 1  
Old 02-05-2008
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
Code:
grep ".proc" file.txt

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

Please help

Thanks
# 2  
Old 02-05-2008
someone post the similar problem as mine.

It is to remove .null T from 'M000071.null T'
The script
Code:
echo 'M00071.null T' | sed 's#^\(M[0-9][0-9]*\)[.]null.*#\1#'

works

I try
Code:
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
# 3  
Old 02-05-2008
Why don't you simply do this:

Code:
$ 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
# 4  
Old 02-05-2008
Code:
 cat file.txt | awk -F '\\$\\$' '{print $1}'

# 5  
Old 02-06-2008
And another one:

Quote:
awk '{ print substr ( $0, 1, index($0, "$$") -1) }' file.txt
or:

Quote:
awk -F'[$$]' '{print $1}' file.txt
# 6  
Old 02-06-2008
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
# 7  
Old 02-06-2008
Quote:
Originally Posted by tiger99
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
Code:
grep ".proc" file.txt

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

Please help

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove part of the line from start of the line?

Hello, I am java command from a shell script which will generate the below output on the command prompt signature Base64 :... (10 Replies)
Discussion started by: chetanojha
10 Replies

2. Shell Programming and Scripting

Remove part of the file using a condition

Gents, Is there the chance to remove part of the file, Taking in consideration this condition. For each record the first row start with the string % VE should be 56 rows for each records.. first row = % VE last row = % sw total 56 rows for each record. Then in the case that the... (4 Replies)
Discussion started by: jiam912
4 Replies

3. Shell Programming and Scripting

How to remove the date part of the file?

Hi Gurus, I have file name like: abcd.20131005.dat I need to remove mid part of data final name should be abcd.dat thanks in advance (2 Replies)
Discussion started by: ken6503
2 Replies

4. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

5. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

6. Shell Programming and Scripting

Remove bracket part

Hi I have to remove in a file in first column whatever is written in brackets with brackets so one file hgfd 123 gfhdj 483 jdgfdg 34738 the output shuld be hgfd 123 gfhdj 483 jdgfdg 34738 (9 Replies)
Discussion started by: manigrover
9 Replies

7. Shell Programming and Scripting

Remove part of a string from second field

I have a file in below format (pipe delimited): 1234__abc|John__abc|xyz 3345__abc|Kate__abc|xyz 55344|Linda__abc|xyz 33434|Murray|xyz I want to remove any occurence of "__abc" in the second field of this file. I did some research and found a way to replace the entire second field with... (5 Replies)
Discussion started by: rajv
5 Replies

8. Shell Programming and Scripting

Using Sed to remove part of line with regex

Greetings everyone. Right now I am working on a script to be used during automated deployment of servers. What I have to do is remove localhost.localdomain and localhost6.localdomain6 from the /etc/hosts file. Simple, right? Except most of the examples I've found using sed want to delete the entire... (4 Replies)
Discussion started by: msarro
4 Replies

9. Shell Programming and Scripting

Remove part of the file

I have an xml file, from where I need to take out Application2 entries and keep the others. I need to remove from <product> to </product> and the key element to look for while removing should be <application> as other pairs can be same for others. <product> ... (10 Replies)
Discussion started by: chiru_h
10 Replies

10. Shell Programming and Scripting

remove certain part of file name

Hi, Is it possible to remove the first part of the file name using find. i.e i have something like 2006abc.txt , 1007bed.txt etc, I wanna rename them to abc.txt , bed.txt I tried some stupid way.. find . -name '*.txt' -exec mv {} `cut -f2-5 -d"_" {}` \; somehow iam not getting it. ... (3 Replies)
Discussion started by: braindrain
3 Replies
Login or Register to Ask a Question