sed to isolate file paths separated by a pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed to isolate file paths separated by a pattern
# 1  
Old 04-24-2009
sed to isolate file paths separated by a pattern

Hi,

I've been searching for a quick way to do this with sed, but to no avail.

I have a file containing a long series of (windows) file paths that are separated by the pattern '@'. I would like to extract each file path so that I can later assign a variable to each path.

Here is the file:

C:\Documents and Settings\My Documents\MATLAB@C:\Documents and Settings\My Documents\MATLAB\a.zip@C:\Documents and Settings\My Documents\MATLAB\f.bhdr@C:\Documents and Settings\My Documents\MATLAB\f_000.bshort@C:\Documents and Settings\My Documents\MATLAB\f_000.hdr@C:\Documents and Settings\My Documents\MATLAB\f_004.bshort@C:\Documents and Settings\My Documents\MATLAB\f_004.hdr@
C:\Documents and Settings\My Documents\MATLAB@C:\Documents and Settings\My Documents\MATLAB\test.nii.gz@C:\Documents and Settings\My Documents\MATLAB\test.zip@C:\Documents and Settings\My Documents\MATLAB\test2.txt@C:\Documents and Settings\My Documents\MATLAB\tmp.tiff@

And I would like the output to be:

C:\Documents and Settings\My Documents\MATLAB
C:\Documents and Settings\My Documents\MATLAB\a.zip
C:\Documents and Settings\My Documents\MATLAB\f.bhdr
C:\Documents and Settings\My Documents\MATLAB\f_000.bshort
C:\Documents and Settings\My Documents\MATLAB\f_000.hdr
C:\Documents and Settings\My Documents\MATLAB\f_004.bshort
C:\Documents and Settings\My Documents\MATLAB\f_004.hdr
C:\Documents and Settings\My Documents\MATLAB
C:\Documents and Settings\My Documents\MATLAB\test.nii.gz
C:\Documents and Settings\My Documents\MATLAB\test.zip
C:\Documents and Settings\My Documents\MATLAB\test2.txt
C:\Documents and Settings\My Documents\MATLAB\tmp.tiff

I can sort-of get there with something like:

sed 's,^\(.*@\)\?\([^@]*\),\1,'

in a loop or something like that, but I was hoping for a simpler (a one-liner maybe?) or a more elegant solution. If anyone can help, I would greatly appreciate it. Thanks in advance!
# 2  
Old 04-25-2009
many ways to achive this

cat filename | tr "@" "\n"

or

awk 'BEGIN{RS="@"}{print}' filename


or

sed '/\@/s//\n/g' filename


cheers,
Devaraj Takhellambam
# 3  
Old 04-25-2009
perfectly beautiful, thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strip the first record off a file and isolate fields off of it

I have a 2 part question on how to this in unix scripting using kshell or c shell. I have a file described below: 1st record has 2 fields on it every other record has 22 fields on it. Example ABC, email address Detail 1 Detail 2 Detail 3 . . . 1st question is... (4 Replies)
Discussion started by: jclanc8
4 Replies

2. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

3. Shell Programming and Scripting

Isolate text with sed or similar utility

All, I'm getting a list like the following and I'd like to kill each PID in turn. pid (17797) pid (21748) pid (21754) pid (21704) pid (2199) pid (2159) pid (17809) pid (21769) pid (21778) pid (21715) ... (3 Replies)
Discussion started by: ejianu
3 Replies

4. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

5. UNIX for Dummies Questions & Answers

I need to isolate a date in a large log file

I wrote head -n1 example.log I grab the first line of the log, but I need to isolate just the date, which is 08/May/2012:09:52:52. I also need to find the reverse of this, which would be tail... http://i.imgur.com/Lp1eBD0.png Thanks in advance (4 Replies)
Discussion started by: spookydll
4 Replies

6. Shell Programming and Scripting

Store and isolate bad pages from a file to new file

I have a file like below . The good pages must have 3 conditions : The pages that containing page total only must have 50 lines. The pages that containing customer total only must have 53 lines. The last page of Customer Total should be the last page. How can I accomplish separating good... (1 Reply)
Discussion started by: ehabaziz2001
1 Replies

7. Shell Programming and Scripting

awk: isolate a part of a file name

hi there, i have a file named 'x20080613_x20100106.pwr1.gc', i want to isolate the part 'x20080613_x20100106' but by using the following line i isolate the part '.pwr1.gc': `awk '$0=substr($0, length($0)-7)' $temp` how can i reverse that? thank you! (3 Replies)
Discussion started by: friend
3 Replies

8. Shell Programming and Scripting

SED: Removing Filenames From Paths

I'm using a script with a lot of SED commands, in conjunction with grep, cut, etc. I've come up against a wall with a particular road block: I output a file from an SVN registry that gives me a list of files. The list consists of a variable number of lines that contain a path/file. The paths... (4 Replies)
Discussion started by: Brusimm
4 Replies

9. UNIX for Dummies Questions & Answers

validate a pattern of numbers that are comma separated

Hi, I have a requirement wherein, I need to validate a user input of the numbers that are comma separated. E.g . The input should be in the format 1,2,3...n (count of numbers is not known) . The user has to mention the input in this format, else it should exit from the program. ... (5 Replies)
Discussion started by: 12345
5 Replies

10. Shell Programming and Scripting

Isolate and Extract a Pattern Substring (Digits Only)

Hi guys, I have a text file report generated from egrepping multiple files. The text files themselves are obtianed after many succesive refinements, so they contain already the desired number, but this is surrounded by unwanted characters, newlines, spaces, it is not always at the start of the... (6 Replies)
Discussion started by: netfreighter
6 Replies
Login or Register to Ask a Question