The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 03-19-2007
Janus Janus is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 18
Cut -d Question

I went through quite a few threads and didn't find anything on this. I also looked on other sites and couldn't turn up an answer.

For completeness sake, I'm working off of solaris 10 in the korn shell environment.

I wrote a script for a buddy to help him out with the following issue.

He has a directory of files, here is an example of one of the files

verylongstringofmixedcharacters==-=-23480732.pdf

He wanted to write a script to remove everything from the "==-=-" and the numbers after it so the file would look like the following:

verylongstringofmixedcharacters.pdf

Utilizing the "cut -d= -f1" command and the "cut -d. -f2" command, I was able to pull off the "verylongstringofmixedcharacters" and the "pdf" part. I then set a new variable name to using the following line:
fileparts=`echo $filepart1'.'$filepart2`

That's not the whole script, but that's the piece where the new filename is created to what he desired. When I finished it and sent it off, he gave me the bad news that sometimes within the verylongstringofmixedcharacters there can be found an = sign. So it might be "verylong=stringof=mixedcharacters", thereby not allowing my first delimiter of = to work. My question to you all is the following:

Is there a way to have a multicharacter delimiter with cut? Meaning, could it be, "cut -d==-=- -f1"? I've tried it the following ways and I received an invalid delimiter messages:

cut -d==-=- -f1
cut -d"==-=-" -f1
cut -d'==-=-' -f1
cut -d "==-=-" -f1
cut -d '==-=-' -f1

I'm thinking I'll have to use a sed command of sorts to fix this. I'm looking into sed one liners that might help after I post this, but I figure I stimulate your brains with it. Thanks in advance for your help.
~Ryan
 

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0