![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|