I want to append values to same string variable inside a recursive function that I have .. I do not want to write to any file but use a variable..
Can anyone please help with it? Thanks in advance.
Thanks for reply but this wont serve my purpose .. As i need to use that inside a recursive loop.
Let me provide example of what i need to do..
I have data in form of index but in words not numbers. I need to write that as shown
I need to go down one level till i find _ at end of string , that is why using recusive function. I will keep appending in the string variable with each call to recursive function and return to previous level once there is no more _'s.
Sample DATA::
OUTPUT
I need to write it in form:
------------------------------------------------------------
I have the function body i need help with defining the variable string .
Thanks in advance.
I gave up the idea of using string variable as it keeps growing larger with each recursive function the control goes in rather than maintaining a value when control comes back at a given level .i.e.
I am trying to implement it by using array variable but Cant seem to make head way as of now ?
Thanks for reply but this wont serve my purpose .. As i need to use that inside a recursive loop.
Let me provide example of what i need to do..
I have data in form of index but in words not numbers. I need to write that as shown
I need to go down one level till i find _ at end of string , that is why using recusive function. I will keep appending in the string variable with each call to recursive function and return to previous level once there is no more _'s.
Sample DATA::
OUTPUT
I need to write it in form:
------------------------------------------------------------
I have the function body i need help with defining the variable string .
Thanks in advance.
firstly i m not be sure that's the way is best solution but i just tried something.
well,let me try to explain as much as i ..
i removed "k" variable because of it's unnecessary..maybe more revisions can be done..
-> [[ if pattern has only like "string_" then delete array named "d".
[[part of `delete array` actually will be used later for new starts (for example Maths_ or "English_" string]]
-> [[ when the line number is greater than 1,then process on the records ]]
-> [[ if the record ($0) has spaces then remove its. ]]
-> [[ if pattern matchs "string_" ]]
then
[[ a[0]=string_ and create array named "d" and d[x] elemnt = d[x] and a[0] (a[0] equals "string_" like "geometry_") ]]
-> [[ print d[x] element and w is zero ( just think as a write/print control) ]]
-> increase `w` (w is actually both print_control and index for added records (from d[x]=d[x]"/"a[0] )
-> [[ if we dont have "string_" (like "circles" line) my goal must be remove last of the array element (d[x]) (`w` times)
here is what `w` for index for "with "_" or non"_" strings ]]
-> [[ remove end of the array element
[[for example my goal must be `Maths/geometry/squares` to `Maths/numbertheory`
so must remove 2 times and add ("numbertheory") to end of array element []d[x][]
[[(actually array is not mandatory to use,but i like arrays )]]
-> [[ and new record is d[x-1] [another array element]]]
-> [[remove spaces if has ]]
-> [[print both d[x] and d[x-1] [[ end of if loop ]]
-> [[ remove last of the array element (d[x]) (`w` times) from the d[x]
so we get a new array with main d[x] and re-start from it for same operations and both states which for new or else (else portion of if-else) ]]
I was using below script to grep one file. I need to append the output using prefix
Data of all-Vms-1.txt
server-1 frame-1 LUN001
server-2 frame-1 LUN002
Data of all-vm-unix.txt
server-1 24
server-2 50
Script used
while read -r g h ;
do
cat all-Vms-1.txt |grep... (5 Replies)
How to pre-append a variable string to each line in a file contains both single and double quotes?
The variable string has no quotes in it.
thank you very much.
:confused: (8 Replies)
Hi All,
I'm trying to insert a string into a file at a specific location.
I'd like to add a string after the parent::__construct(); in my file.
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
function... (6 Replies)
Hi Team!!
Please can anyone tell me why the following line does not work properly?
str3+=$str2
it seems that str3 variable does not keep its value in order to be concatenated in the next iteration! Thus when i print the result of the line above it returns the str2 value
What i want to do is to... (8 Replies)
Hi,
I need to replace and append a string in a text if grep is true. For eg:
grep ABC test.txt | grep -v '\.$' | awk {'print $4'} | sed "s/ ?
How do I replace all instances of "print $4" using sed with another sring? Eg of the string returned will be,
lx123
web222
xyz
Want to... (8 Replies)
Hello, could you please help with this one. I have an input file like this:
123,4567,89000
123456789,9876543,12
and for the output I need strings to be with the fixed length, let's say 15, and if the string is -lt 15 to be populated with blanks at the end until it reach 15, like this:
123 ,4567... (1 Reply)
Right now, my code is:
s/Secondary Ins./Secondary Ins.\
1/g
It's adding a 1 as soon as it finds Secondary Ins.
Primary Ins.: MEDICARE B DMERC Secondary Ins.
1: CONTINENTAL LIFE INS
What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Okay -- I hope I ask this correctly.
I'm working on my little shell script to write vendor names and aliases to files from user input. If a user choose to add to a file, he can do that as well. I'm using a select loop for this function to list all the possible files the user can choose from.... (7 Replies)
Hi,
I need to generate the text name dynamically in for loop,
ex,
VAR_COPY_FILE1= file path 1
VAR_COPY_FILE2= file path 2
VAR_COPY_FILE3= file path 3
for i in 1 2 3
do
if
then
"do some process here"
fi
done (3 Replies)