Find and delete rest of the line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and delete rest of the line
# 1  
Old 08-18-2010
Error Find and delete rest of the line

i need to find ' - ' in a line , if i found i need to rest of the line including '-'

example
Code:
libmm-2.0
libytytsunos-5.6

output
Code:
libmm
libytytsunos

# 2  
Old 08-18-2010
something like this,
Code:
sed 's/-.*//g' infile

These 2 Users Gave Thanks to pravin27 For This Post:
# 3  
Old 08-18-2010
Or this:
Code:
awk -F- '{print $1}' infile

These 2 Users Gave Thanks to kevintse For This Post:
# 4  
Old 08-18-2010
if values in variables
Code:
for VAR in "libmm-2.0" "libytytsunos-5.6"
do  echo ${VAR%%-*}
done

This User Gave Thanks to frans For This Post:
# 5  
Old 08-18-2010
Code:
cut -d \- -f1 < urfile

This User Gave Thanks to rdcwayx For This Post:
# 6  
Old 08-19-2010
Thanks for all u ...
It worked
# 7  
Old 08-21-2010
Quote:
Originally Posted by frans
if values in variables
Code:
for VAR in "libmm-2.0" "libytytsunos-5.6"
do  echo ${VAR%%-*}
done

Nice.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

2. Shell Programming and Scripting

Find the text in the file and delete the rest of the line.

Hi, I have one requiremnet like this. I need to find some particular string (eg.IncludeDateTime = ) in a file. And wherever it finds the string the unix script has to delete the remaining text coming after the string (ie., 'IncludeDateTime = ' ) in the same line. I tried to write this script in... (5 Replies)
Discussion started by: jannusuresh
5 Replies

3. UNIX for Dummies Questions & Answers

find string and get the rest of the line in a pipe delimited file

Hi friends, I have a file where I should search for a string and get the rest of the line but without the delimiter using awk. for example I have the series of string in a file: input_string.txt bbb ccc aaa and the mapping file looks like this. mapping.txt aaa|12 bbb|23 ccc|43... (11 Replies)
Discussion started by: kokoro
11 Replies

4. Shell Programming and Scripting

awk delete/remove rest of line on multiple search pattern

Need to remove rest of line after the equals sign on search pattern from the searchfile. Can anybody help. Couldn't find any similar example in the forum: infile: 64_1535: Delm. = 86 var, aaga 64_1535: Fran. = 57 ex. ccc 64_1639: Feb. = 26 (link). def 64_1817: mar. = 3/4. drz ... (7 Replies)
Discussion started by: sdf
7 Replies

5. Shell Programming and Scripting

Find specific line and delete line after.

I'm looking for a way to search a file, in this case init.rc for a specific match, service adbd /sbin/adbd, and delete the a specific line after it Original: # adbd is controlled by the persist.service.adb.enable system property service adbd /sbin/adbd disabled After deletion: #... (5 Replies)
Discussion started by: GabrialDestruir
5 Replies

6. Shell Programming and Scripting

Delete rest of line with sed works on Linux but not on Solaris

Hi all, Our application installation uses "sed" command to delete rest of line. It work perfect on Linux but fail on Solaris. The OS versions are Solaris 9 and Linux Red Hat AS 3. yourfile.txt hello and world cat and dog hello world in linux: cat yourfile.txt | sed ‘s/\(\+\)... (3 Replies)
Discussion started by: javac2005
3 Replies

7. UNIX for Dummies Questions & Answers

Find Pattern delete line and next line

I am trying to delete the line with pattern and the next line. Found the below command in forum which also deleted the previous line. how should i modify that to make sure that only the line with pattern and the next line are deleted but not the previous line? awk '/key... (1 Reply)
Discussion started by: rdhanek
1 Replies

8. UNIX for Advanced & Expert Users

Find and delete the line

Hi I have a text file like this name today.txt the request has been accepted the scan is successful at following time there are no invalid packages 5169378 : map : Permission Denied the request has been accepted Now what i want do is I want to search the today.txt file and if i... (8 Replies)
Discussion started by: gsusarla
8 Replies

9. Shell Programming and Scripting

find a line and delete it.

Hi All, I would like to fine some entry in a file, if it found, it should remove the same in the same file. Please some one help me. need to find and en entry 'bea' from hosts file. If it found it should write it same host file. but i am not geting it. If i am writing it in new file... (2 Replies)
Discussion started by: bullz26
2 Replies

10. UNIX for Advanced & Expert Users

Delete rest of the line

Hi, can anyone please answer my question in deleting the rest of the line. I have an example below of a file contaning: Serial3/1.5 43.70.195.13 YES NVRAM down down Serial3/3 225.94.155.69 YES NVRAM up down Serial3/6 ... (3 Replies)
Discussion started by: Aejaz
3 Replies
Login or Register to Ask a Question