sed: -e expression #1, char 0: no previous regular expression
Hello RodiC & Alister,
Im using bash. My code is now running fine with no error.
1. I first tried to assign the elements manually like:
The above works.
2. Also, limiting size to 1 down and counting from 0 works.
Thanks both of you for hitting the nail.Appreciate it!
Regards,
Indu
Last edited by InduInduIndu; 08-20-2012 at 11:40 AM..
Reason: mistakenly hit the enter key before
<snip>
Im using bash <snip>
1. I first tried to assign the elements manually like:
The above works.
Does it? I'm not sure I understand what you are doing there. In the while loop, you say you are populating array arr from a file. How do you know when to terminate the loop, and what do you expect from the ${#arr$} construct? And how do you assign an element from a file to member arr[$i]?
Quote:
2. Also, limiting size to 1 down and counting from 0 works.
You say (post #8) that you are using bash. Array indexing in bash starts from 0 and counts up to ${#arr[@]} - 1 , as stated earlier. In both your posts #8 and #10, you are starting the while loop for array indexing at 1 (i=1 or j=1). So you will be missing the first element in your problem_arr! And in either post you are NOT using the correct method to evaluate the number of elements in the array, which I duplicated above. Btw, the way you assign your problem_arr will not work, as it does not result in an array but in a single variable with n space separated words.
Really Sorry RodiC i couldn't exactly copy pasted my script here coz the script lies in the system where this site is blocked. I'd need to make hell lot of effort to exactly copy paste code. So i just tried to simulate the problem here above.
Yes, You are right! so many things which i abstracted here considering those are kind of implicit.
And i haven't missed any element if i have assigned elements from index 1 to size of array. However, if i had used indexing from 0, i would have limit loop to size-1.
Anyways, appreciate your effort to come forward for understing the real problem. You are simply awesome!!
Hi , I need to remove pipe character from a |^ delimeted file.
Something like |^tran|sformers||^|revenge |of fallen|^ to
|^transformers|^revenge of fallen|^...
Cold anybody please help to build the regular expression using sed .
many thanks.
Please use code tags next time for... (1 Reply)
Hi all,
How am I read a file, find the match regular expression and overwrite to the same files.
open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat";
open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat";
while (<DESTINATION_FILE>)
{
# print... (1 Reply)
I have read many threads, but I still didn't find the right answer. May be i didn't find the right thread, though are so many threads for the same question.
Basically the situation is - find date in a file and replace it with another date. (its not homework, its part of lot of a big processing,... (10 Replies)
Hi ,
I am learing sed
echo abc 123 def 456 | sed 's|\(*\) \(*\)|\1|'
is returning abc def 456
i was hoping abc def "\1" should only print the occurence of the first pattern
but according to my understanding it is just removing the first occurence of the second pattern... (7 Replies)
CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error.
source $CA_VERSION_DATA
if * ]
then
echo "CA_RELESE $CA_RELEASE is invalid"
exit -1
fi
+ source /etc/ncgl/ca_version_data
++ CA_PRODUCT_ID=samxts
++ CA_RELEASE=6
++ CA_WEEK_NO=7
++... (3 Replies)
please consider this:
echo "11111*X*005010X279~ST*270*1111111*005010X279~BHT*0011*11" | sed 's/.*\(005010X(\d)(\d)(\d)*\).*$/\1/'i'm searching for first occurrence of 005010X while leaving rest of characters out.
:confused:
any tips? thnx in advance guys. (7 Replies)
Hi
I need to get text that are within ""
For example
File:
asdasd "test test2" sadasds asdda asdasd "demo demo2"
Output:
test test2 demo demo2
Any help is good
Thank you (12 Replies)
Hi!
I'm trying to write a regexp but I have no luck...
I have a string like this:
param1=sometext¶m2=hello¶m3=bye
Also, the string can be simply:
param2=hello
I want to return the value of param2: "hello".
How can I do this?
Thanks. (3 Replies)
Hi,
I'm trying following:echo "test line XA24433 test" | sed 's/.*X\(.*\)/X\1/'
XA24433 test While I want the output as: XA24433
I want to grab the words starting with letter X till the next space, this word can be anywhere in the line. (9 Replies)