Removing the rest of line from the second entry of an expression


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Removing the rest of line from the second entry of an expression
# 1  
Old 10-17-2008
Java Removing the rest of line from the second entry of an expression

Dear people, can you please enlighten:
I need to do a (most probably) very simple thing but couldn't figure how.

I have files with lots of lines starting with a fixed expression:

Query=. (the dot is a space)

followed by different combinations of characters including special ones such as pipe (|), and I need to find the second space in the line and remove the rest of line starting from this second space.

Is that possible to to this with SED? or is there a script needed?

thanks much in advance for help!
# 2  
Old 10-17-2008
Assuming you only want to change lines beginning with "Query=":

Code:
sed '/^Query=/s/\([^ ]* [^ ]*\) .*/\1/' file > newfile

Regards
# 3  
Old 10-20-2008
thanks much! works fine Smilie
# 4  
Old 10-20-2008
Quote:
Originally Posted by Franklin52
Assuming you only want to change lines beginning with "Query=":

Code:
sed '/^Query=/s/\([^ ]* [^ ]*\) .*/\1/' file > newfile

Regards
but what if in my strings starting with the "Query=" I wanted to change all spaces into, say, '_' except for the first space in the string (the contents of strings differ except for the marking 'Query=')?
Couldn't figure how to do this with regions..

thanks much for help!
# 5  
Old 10-20-2008
Code:
sed -e 's/ /_/g' -e 's/_/ /1' file

# 6  
Old 10-20-2008
thanks a lot !_!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing rows that contain non-unique column entry

Background: I have a file of thousands of potential SSR primers from Batch Primer 3. I can't use primers that will contain the same sequence ID or sequence as another primer. I have some basic shell scripting skills, but not enough to handle this. What you need to know: I need to remove the... (1 Reply)
Discussion started by: msatseqs
1 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

How to substitute a line that matches an expression with another line

I need some help. I have a file (all.txt) whereby I want to substitute using sed/awk all lines that matches an expression with another line with different expression i.e subtitute expression, database_id: filename; WITH database_id: PY; There are many occurrences of the expression... (4 Replies)
Discussion started by: aimsoft
4 Replies

6. Shell Programming and Scripting

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 libmm-2.0 libytytsunos-5.6 output libmm libytytsunos (7 Replies)
Discussion started by: girija
7 Replies

7. 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

8. Shell Programming and Scripting

Search a string and print the rest of line

Hi Guys, I need to search a string and print the rest of the lines... input: 8 0 90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n output: 00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n Actually i don even need the first "00".. any suggestions is appreciated..... (13 Replies)
Discussion started by: mac4rfree
13 Replies

9. Shell Programming and Scripting

Maximum value of each line entry

Dear power users, I have a file like this: AA 8 AA 6 AA 5 AA 4 AA 3 BB 9 BB 4 BB 3 BB 2 ZZ 5 ZZ 3 ZZ 1 ... The characters in colum one are variously different until the end of the file. I want to extract the maximum value of each entry in... (3 Replies)
Discussion started by: kecopx
3 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