Split a line based on : using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split a line based on : using sed
# 1  
Old 01-19-2010
Question Split a line based on : using sed

Hi,

i have a file say file1 having following data

/abc/def:ghi/jkl/ some other text

Now i want to extract only ghi/jkl/using sed, can some one please help me.

Thanks
Sarbjit
# 2  
Old 01-19-2010
Code:
echo '/abc/def:ghi/jkl/' | sed 's/.*:\(.*\)/\1/'

# 3  
Old 01-19-2010
Code:
sed 's/[^:]*://' infile



---------- Post updated at 07:47 ---------- Previous update was at 07:29 ----------

Oops you wanted "some other text" removed
Code:
sed 's/[^:]*://;s/ .*//' infile

-or-
Code:
sed -e 's/[^:]*://' -e 's/ .*//' infile

-or-
Code:
sed 's/[^:]*:\([^ ]*\) .*/\1/' infile

-or-
Code:
awk -F"[: ]" '{print $2}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a line into multiple lines based on delimeters

Hi, I need help to split any lines that contain ; or , input.txtAc020 Not a good chemical process AC030 many has failed, 3 still maintained AC040 Putative; epithelial cells AC050 Predicted binding activity AC060 rodC Putative; upregulated in 48;h biofilm vs planktonic The output... (8 Replies)
Discussion started by: redse171
8 Replies

2. Shell Programming and Scripting

How to split a file based on pattern line number?

Hi i have requirement like below M <form_name> sdasadasdMklkM D ...... D ..... M form_name> sdasadasdMklkM D ...... D ..... D ...... D ..... M form_name> sdasadasdMklkM D ...... M form_name> sdasadasdMklkM i want split file based on line number by finding... (10 Replies)
Discussion started by: bhaskar v
10 Replies

3. Shell Programming and Scripting

Split a file into multiple files based on line numbers and first column value

Hi All I have one query,say i have a requirement like the below code should be move to diffent files whose maximum lines can be of 10 lines.Say in the below example,it consist of 14 lines. This should be moved logically using the data in the fisrt coloumn to file1 and file 2.The data of first... (2 Replies)
Discussion started by: sarav.shan
2 Replies

4. Shell Programming and Scripting

AWK/SED line based search

Hi, I have a file with values like this 1 11 2 11 3 44 4 55 5 66 (an representative of what I have). I want to split this file into smaller files based on column 1 values (values within a range). The issue that I am facing is that the file is really big, and takes too long to... (21 Replies)
Discussion started by: new_one
21 Replies

5. Web Development

split line based on delimeter SQL

I have a SQL query SELECT BLAH_ID, BLAH_CODE, DATEFORMAT(CALENDAR_DATE, 'MM-DD-YYYY') AS CALENDAR_DATE_STR, HOURS, 'N', FROM blah_tmp_tbl order by CALENDAR_DATE_STR,BLAH_ID,BLAH_CODE; OUTPUT TO 'MyExport.CSV' quote '' FORMAT ASCII; That gets me the below output; ... (2 Replies)
Discussion started by: ffdstanley
2 Replies

6. Shell Programming and Scripting

Split line to multiple files Awk/Sed/Shell Script help

Hi, I need help to split lines from a file into multiple files. my input look like this: 13 23 45 45 6 7 33 44 55 66 7 13 34 5 6 7 87 45 7 8 8 9 13 44 55 66 77 8 44 66 88 99 6 I want to split every 3 lines from this file to be written to individual files. (3 Replies)
Discussion started by: saint2006
3 Replies

7. Shell Programming and Scripting

Split File Based on Line Number Pattern

Hello all. Sorry, I know this question is similar to many others, but I just can seem to put together exactly what I need. My file is tab delimitted and contains approximately 1 million rows. I would like to send lines 1,4,& 7 to a file. Lines 2, 5, & 8 to a second file. Lines 3, 6, & 9 to... (11 Replies)
Discussion started by: shankster
11 Replies

8. Shell Programming and Scripting

Split a file based on pattern in awk, grep, sed or perl

Hi All, Can someone please help me write a script for the following requirement in awk, grep, sed or perl. Buuuu xxx bbb Kmmmm rrr ssss uuuu Kwwww zzzz ccc Roooowwww eeee Bxxxx jjjj dddd Kuuuu eeeee nnnn Rpppp cccc vvvv cccc Rhhhhhhyyyy tttt Lhhhh rrrrrssssss Bffff mmmm iiiii Ktttt... (5 Replies)
Discussion started by: kumarn
5 Replies

9. Shell Programming and Scripting

Split a huge line into multiple 120 characters lines with sed?

Hello , I'm trying to split a file which contains a single very long line. My aim is to split this single line each 120 characters. I tried with the sed command : `cat ${MYPATH}/${FILE}|sed -e :a -e 's/^.\{1,120\}$/&\n/;ta' >{MYPATH}/${DEST}` but when I wc -l the destination file it is... (2 Replies)
Discussion started by: jerome_1664
2 Replies

10. UNIX for Advanced & Expert Users

sed help split line

hi i have a file containing lines like word1,word2,word3,word4,.. word4,word5,word3,word6,... now i need to make it to look like word1 word2 word3 word4 . . . in other words ','(comma) is replaced with new line. (5 Replies)
Discussion started by: Raom
5 Replies
Login or Register to Ask a Question