So whats the final output? Do you want "travelID IDNumber;" to be there or remove it?
Also are there multiple patterns/blocks like this? Are they sequential?
---------- Post updated at 04:22 PM ---------- Previous update was at 04:08 PM ----------
sorry again ... iwant bit more generic way to do it as i will have varying list.
in the above case they are only 4 pin code entries so file will look like
4
(
111111
222222
333333
4444444
)
if i have 5 pincodes then one more pincode ll be added in the list as
5
(
111111
222222
333333
4444444
555555
)
so copying IDNumber and pasting before 4 or 5 should be in more generic way
it works fine but printing on terminal, how can i save it? in fact i want to overwrite it.
sorry for bothering you but at the end i need ; after closing bracket like this
Thank you very much.
I have a question, In mean time i tried with different files.
some of my files have IDNumb only 6 letters
n files i created have IDNumber its 8 letters ...
also some ppl write these output files with TrvlID again 6 letters instead of travelID....
I just dont want to bother them ...infact you as well ..but need some help...
can u explain the code how it is working?
Sorry for bothering you
Regards,
linuxUser_
---------- Post updated at 05:57 PM ---------- Previous update was at 05:42 PM ----------
its working perfectly for all cases ...sorry
Thanks a lot
It works as you see. If you have basic understanding of awk , It works in /pattern/ {action} mode.
awk -v newLocation=Bangalore ' #define awk variable newLocation
/^location/ {$2=newLocation";"} #look for location line and replace $2 with newLocation plus ";" at the end
/^travelID/ {tID=$2;gsub(";$"," ",tID)} #look for travelID line and store the $2 with tID variable, gsub is to remove the ";" from the end
/^\}$/ {f=1} #look for line contains "}" and set a flag f to true
f==1 && /^[0-9]+$/ {$0=tID $0;f=0} #look for line immd followed by the upper criteria AND contains only numbers, prefix the file with variable tID
/^\)$/ {$0=$0";"} #suffix ";" after ")"
{print}' file > new_file #print all the lines.
---------- Post updated 05-08-14 at 12:08 AM ---------- Previous update was 05-07-14 at 06:44 PM ----------
Hi again,
Let me guess you have great touch with C++ as well.
Sorry to bother you. I need little help in shell operations from C++ program.
Here I furnish the details of problem:
Lets say my current working path is myWorkingPath.
In my working path I have list of name directories and each name directory has two more sub directories say A/B.
(now path to B will be pathB = myWorkingPath/name/A/B)
I have a executable (say run) in myWorkingPath directory, that i wanted to execute from B directory.
From C++ program I can do shell operations like mkdir, rm etc using system("mkdir NewDir"), system("rm file") etc., (these shell operations will done form myWorkingPath)
but unable to do some shell operations from pathB. How can I communicate pathB for system() operations?
lets say I have saved this path in
pathB="/home/linuxUser/myWorkingPath/name/A/B"
. here name is a variable.
for(i=0;i<nameList.size(); i++){
pathB="/home/linuxUser/myWorkingPath"/nameList.name(i)/"A/B";
system("cd pathB"); // to goto that B directory
system("../../../run"); // to run the executable
}
I know this program is wrong but, may give you clear idea what i wanted to do.