11-01-2009
Sed to print a string until the second occurrence of a character
Hi, I am totally new to shell scripting.
I have a String "c:\working\html\index.txt.12-12-2009.bkp" I want to check if the string has more than one "." character. If it does I would like to retrieve only "c:\working\html\index.txt" i.e, discard the second occurrence of "." and the rest of the string, using Sed command.
The closest I could get to is the following Sed command.
$ echo "c:\working\html\index.txt.12-12-2009.bkp" | sed 's/.*[.]//'
result -> bkp
but it seems sed works from right to left of the string and so finds the last occurrence of the "." returning bkp.
I am using Cygwin to run these commands.
Sed version is "GNU sed version 4.1.5"
bash version si "GNU bash, version 3.2.49(22)-release (i686-pc-cygwin)"
TIA. imr
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi all,
I have a text file with following content
PAGENUMBER
asasasa
asasasa
PAGENUMBER
sasasasasa
PAGENUMBER
using sed i want to replace PAGENUMBER by occurrence count
eg
1
asasasa
asasasa
2
sasasasasa
3 (4 Replies)
Discussion started by: uttamhoode
4 Replies
2. Shell Programming and Scripting
Ok,
So I have a huge file that has over 12000 lines in it.
in this file, there are 589 occurrences of the string "use five-minute-interval" spread in various areas in the file.
How can i replace the the last 250 of the occurrences of "use five-minute-interval" with "use... (10 Replies)
Discussion started by: SkySmart
10 Replies
3. Shell Programming and Scripting
Thanks for the help yesterday. I have a little modification today,
I am trying the following:
i have a log file of a webbap which logs in the following pattern:
2011-08-14 21:10:04,535 blablabla ERROR Exception1 blablabla
bla
bla
bla
bla
2011-08-14... (2 Replies)
Discussion started by: ppolianidis
2 Replies
4. Shell Programming and Scripting
Guys,
I am trying the following:
i have a log file of a webbap which logs in the following pattern:
2011-08-14 21:10:04,535 blablabla ERROR blablabla
bla
bla
bla
bla
2011-08-14 21:10:04,535 blablabla ERROR blablabla
bla
bla
bla
... (6 Replies)
Discussion started by: ppolianidis
6 Replies
5. Shell Programming and Scripting
Hi
I have requirement to find nth occurrence in a file and capture data from with in lines (between lines)
Data in File.
<QUOTE>
<SESSION>
<ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/>
<ATTRIBUTE NAME='Service Name' VALUE='None'/>
</SESSION>
<SESSION>
<ATTRIBUTE... (6 Replies)
Discussion started by: tmalik79
6 Replies
6. Shell Programming and Scripting
Hi, i have file f1.txt with data like:
CHECK
a
b
CHECK
c
d
CHECK
e
f
JOB_START
....
I want to match the last occurrence of 'CHECK' until the end of the file.
I can use awk:
awk '/^CHECK/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' f1.txt | tail +2Is there a cleaner way of... (2 Replies)
Discussion started by: ysrini
2 Replies
7. Shell Programming and Scripting
Hi
I need help on this ..!!
Input :
xx_abc_regA
xx_def_regB
xx_qwe_regC
Now i required the output as the below
abc
def
qwe
Need to remove last occurrence of character (_) and rest of the string in Unix (sed).
Thanks in Advance ..!!!
-Nallachand (3 Replies)
Discussion started by: Nallachand
3 Replies
8. Shell Programming and Scripting
Hello
how to find last occurence of a string
for example in the following I want last occurence of '-' i.e. position 12
str="aa-bbb-cccc-ddd-ee"
my pupose is to get the string 'ee'
Thanks and Regards
Chetanz (5 Replies)
Discussion started by: Chetanz
5 Replies
9. Shell Programming and Scripting
Hi,
I would like to know how, using sed, be able to insert contents of file2 in file1 after say the second occurrence of a given string? e.g.
> cat file1
banana
apple
orange
apple
banana
pear
tangerine
apple
> cat file2
I don't like apples
What would be the sed command to insert... (5 Replies)
Discussion started by: dimocn
5 Replies
10. Shell Programming and Scripting
Hi, i have file file.txt with data like:
START
03:11:30 a
03:11:40 b
END
START
03:13:30 eee
03:13:35 fff
END
jjjjjjjjjjjjjjjjjjjjj
START
03:14:30 eee
03:15:30 fff
END
ggggggggggg
iiiiiiiiiiiiiiiiiiiiiiiii
I want the below output
START (13 Replies)
Discussion started by: Jyotshna
13 Replies
VM(1) mgetty VM(1)
NAME
vm - VoiceModem is the program for handling the voice modem functionality from shell scripts
ACTIONS
beep options [<frequency [<length in 0.001sec>]]>
diagnostics options device name (e.g. ttyS2
dial options phone number
help
play options [<file names]+>
record options file name
shell options [<shell script [shell options]]>
wait options [<time in seconds]>
devicetest
OPTIONS
-c n use compression type n
-d n set i/o device
-t, -m, -i, -e, -s, -H equals to -d <2,3,4,5,6,7>
-l s set device string (e.g. -l ttyS2:ttyC0)
-v verbose output
-w use off / on hook signal from local handset to start and stop recording
-x n set debug level
-L n set maximum recording length in sec
-P print first DTMF tone on stdout and exit
-R read and print DTMF string on stdout and exit
-S s set default shell for shell scripts (e.g. -S /bin/sh)
-T n set silence timeout in 0.1sec
-V n set silence threshold to <n> (0-100%%)
SEE ALSO
vgetty(1)
POD ERRORS
Hey! The above document had some coding errors, which are explained below:
Around line 30:
You forgot a '=back' before '=head1'
Around line 32:
'=item' outside of any '=over'
Around line 71:
You forgot a '=back' before '=head1'
perl v5.10.1 2010-04-04 VM(1)