Use of sed to find everything after first match!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of sed to find everything after first match!
# 1  
Old 09-06-2013
Use of sed to find everything after first match!

Hi Guys
So far I have got this to work:
Code:
set x = temp1:temp2:temp3

echo $x | sed 's/.*:\(.*\).*/\1/'
Answer:
temp3

But I want answer as temp2:temp3, that is everything after the first ":" is found. If anybody can help with a bit of description that will be great.

Thanks in Advance
# 2  
Old 09-06-2013
This is very similar to your previous thread. Is there a theme developing, or shall we continue in dribs and drabs?

Code:
# X=1:2:3                                                                                                 
# echo $X | sed "s/[^:]*://"
2:3
# echo ${X#*:} 
2:3

This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting out of sed on first NOT match

i have a large file where i want to look for any record that is is larger or smaller than 21 and if it is the case i want to report and break SED .. how can i achieve it ? i dont want sed to scan the complete file after one non match is found. (4 Replies)
Discussion started by: boncuk
4 Replies

2. Shell Programming and Scripting

sed print from last occurrence match until the end of last occurrence match

Hi, i have file file.txt with data like: START 03:11:30 a 03:11:40 b END START 03:13:30 eee 03:13:35 fff END jjjjjjjjjjjjjjjjjjjjj START 03:14:30 eee 03:15:30 fff END ggggggggggg iiiiiiiiiiiiiiiiiiiiiiiii I want the below output START (13 Replies)
Discussion started by: Jyotshna
13 Replies

3. Shell Programming and Scripting

sed match

Hi can anyone help with the following: echo "Date range on 5th May is between -010516 and 050516- please continue "| sed 's/\(.*-\)\(.*-\)\(.*$\)/\2/' output 010516 and 050516- What i need is to include the - to be included. Desired output: -010516 and 050516- I know... (11 Replies)
Discussion started by: andy391791
11 Replies

4. Shell Programming and Scripting

Find sessionids after match

Hi Guys, I need a help on writing shell scripting where I am stuck on finding keyword after a grep match. file.log (sample) line1 -> ppp dfasf adgasg session out sfsgsgsghsgh line2 -> sdaf agasg sessionid: 1234Nhsh34 sdagsjhsh srhs line3 -> sdgshytnba sessionid: 453omgt thdjdh gfhjdj... (19 Replies)
Discussion started by: TCS
19 Replies

5. UNIX for Dummies Questions & Answers

sed can't match '\n' ?!

Hi: it seems very strange. there is a file with multiple lines. After I squeezed out the consecutive blank lines (and some other text processing), somehow the sed '/\n/! d' file can not generate any output, as if it can't find any line with newline. the file is has many lines, so... (9 Replies)
Discussion started by: phil518
9 Replies

6. Shell Programming and Scripting

find: No match due to find command being argument

I am using csh and getting the error "find: No match." but I cannot figure out why. What I am trying to do is set the find command to a variable and then execute the variable as a command. I ran it through a debugger and it looks like $FIND is getting set but the find command can not actually be... (2 Replies)
Discussion started by: mst3k4l
2 Replies

7. Shell Programming and Scripting

How to find first match and last match in a file

Hi All, I have a below file: ================== 02:53 pravin-root 02:53 pravin-root 03:05 pravin-root 02:55 pravin1-root 02:59 pravin1-root ================== How do I find the first and last value of column 1. For example, how do I find 02:53 is the first time stamp and 03:05 is... (3 Replies)
Discussion started by: praving5
3 Replies

8. UNIX for Dummies Questions & Answers

using sed or grep to find exact match of text

Hi, Can anyone help me with the text editing I need here. I have a file that contains the following lines for example: (line numbers are for illustration only) 1 Hello world fantasy. 2 Hello worldfuntastic. 3 Hello world wonderful. I would like to get all those lines of text that... (5 Replies)
Discussion started by: risk_sly
5 Replies

9. Shell Programming and Scripting

sed: find match and delete the line above

I am searching a dhcpd.conf to find the hardware ethernet match, then once the match is found delete just the line above it. For example: testmachine.example { hardware ethernet 00:00:00:00:00:00; fixed address 192.168.1.100; next-server 192.168.1.101; filename "linux-install/pxelinux.0"; }... (3 Replies)
Discussion started by: cstovall
3 Replies

10. Shell Programming and Scripting

how do I negate a sed match

I have a text file that has links in it. I can write a match for sed to replace the link with anything. For example: http://www.google.com becomes XxX But what I'm after is not to replace the link with something but to remove everything else and just leave the link. I want a... (5 Replies)
Discussion started by: muxman
5 Replies
Login or Register to Ask a Question