remove particular characters using sed
Hi,
file = TT.ParlayX_RequestLog_78653_20101212180044.log.17490 1. Want to remove the characters before the first dot (.) including the dot (.) 2. Want to remove the characters after the last dot (.) including the dot (.) That is, basically, I want the output as: ParlayX_RequestLog_78653_20101212180044.log Please advice Thanks |
Use parameter substitution. In particular look at ${var#pattern} and ${var%pattern}. Feel free to ask if in doubt.
|
Hi,
Is a sed solution really needed? Bash has an elegant way to do this: Assuming the file name is stored in a variable (XXX in this example). This strips the last part (.17490 in your example): Code:
echo ${XXX%.*} Code:
echo ${XXX#*.} Hope this helps. |
Thanks colucix..I'll look into that and if in doubt I'll get back to you...
Thanks druuna..that was fast and short... I tried this: echo TT.ParlayX_RequestLog_78653_20101212180044.log.17490 | sed "s/^TT\.//" file | sed 's/\.[0-9][0-9][0-9][0-9][0-9]//' How can I club the last two seds together and any other way via sed to achieve the above |
Hi,
To string sed statements together: sed -e 's/x/y/' -e 's/a/b/' file Your command would look like this: Code:
echo "TT.ParlayX_RequestLog_78653_20101212180044.log.17490" | sed -e 's/^TT\.//' -e 's/\.[0-9][0-9][0-9][0-9][0-9]//' |
http://sed.sourceforge.net/sed1line.txt
# substitute (find and replace) "foo" with "bar" on each line This is for a line of text in a file This may be more useful, have a read of this forum page and use it as reference for what you want to do. http://programming.itags.org/unix-li...ramming/82536/ This is closer to what you need, but you'l still need the bash interpretation of blocks of strings. http://www.linuxquestions.org/questi...-files-723311/ http://www.ibm.com/developerworks/ai.../section5.html one of my favourites... Changing file extensions, but you still need to define the ($)chars, like $1 is the first part of a line, $2 is the second, etcetera. But you can also define the beginning of a line and the ending of a line without knowing how many parts there are to the line. you could use a bash script, with a for loop... Code:
for i in *.txt; { mv $i $i.doc} Hope this gives you food for thought, I tried to search for a real solution, but did not find one. Therefore I returned to the man pages and google. Cheers Glenn <edit> I'm a bit slow, and still learning sed grep and awk, I think the above examples look good. </edit> |
Quote:
|
Quote:
thanks a lot for your help |
All times are GMT -5. The time now is 07:14 AM. |