![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| extracting domain names out of a text file | totus | Shell Programming and Scripting | 6 | 02-11-2009 08:53 AM |
| Extracting specific text from a file | rahulkav | Shell Programming and Scripting | 8 | 10-22-2008 10:34 AM |
| Extracting a line in a text file | terryporter51 | Shell Programming and Scripting | 5 | 10-13-2008 06:34 PM |
| extracting unique lines from text file | soliberus | Shell Programming and Scripting | 3 | 08-22-2008 10:18 AM |
| extracting a set of strings from a text file | Deanne | Shell Programming and Scripting | 2 | 09-20-2007 11:31 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
extracting text and reusing the text to rename file
Hi,
I have some ps files where I want to ectract/copy a certain number from and use that number to rename the ps file. eg: 'file.ps' contains following text: 14 (09 01 932688 0)t the text can be variable, the only fixed element is the '14 ('. The problem is that the fixed element can appear elsewhere, not followed by a number (eg.14 (Telefoonnummer)t) The number can appear several times in the file, so I only would like to use the firts occurrence. So basicaly it comes to that: file.ps needs to change to 09 01 932688 0.ps Can someone help me with that? Tnx in advance, John |
|
||||
|
Hi Tytalus,
thank you for the quick response but it doesn't seem so work. (I might be doing something wrong, since I'm just starting to try this kind of stuff) The filename has been renamed, but it takes the first line in the file. Therefore I attached the actual ps file. What I forgot to mention is that the filename itself is also variable, so I was wondering whether your solution would work as well with the *.ps in stead of the file.ps? best regards, John PS indeed the underscores are a better solution |
|
|||||
|
oops - my bad..
try: Code:
mv file.ps $(sed -n -e 's/ /_/g' -e '/14/s/.*14_(\([0-9][_0-9]*\).*/\1.ps/gp' file.ps) Code:
for f in * do mv $f $(se..../gp' $f) done HTH |
|
||||
|
Hi Tytalus,
sorry to bother again. when I ran the first line in this thread then I get the ps header. When I ran the second post then it worked once. Today I tried again with the follwing line: mv 0127050_out_0001_0008.ps $( sed -n -e 's/ /_/g' -e '/14/s/.*14_(\([0-9][_0-9]*\).*/\1.ps/gp' 0127050_out_0001_0008.ps) and I got the following: usage: mv [-f | -i | -n] [-v] source target mv [-f | -i | -n] [-v] source ... directory Do you notice something strange in the line I typed? Thanks for the help, I realy appreciate it. |
|
||||
|
Hi again
I know why the output is not correct. The file I sent you only had one occurrence of the 14 (09 01 932688 0)t. The one I want to process got multiple. Is there someone who knows how I get only the first occurrence? When I just run: sed -n -e 's/ /_/g' -e '/14/s/.*14_(\([0-9][_0-9]*\).*/\1.ps/gp' *.ps then I get the following: 09_01_932699_0.ps 09_01_932699_0.ps 09_01_932699_0.ps 5_.ps 5_.ps 5_.ps 09_01_932699_0.ps 5_.ps 09_01_932699_0.ps 5_.ps 5_.ps 5_.ps 09_01_932699_0.ps 5_.ps I would like to have only the first 09_01_932699_0.ps Best Regards, John |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|