I have been thinking about a few things that I have no idea of how to do with a scripting language (awk/sed I know to make proper use of just these 2).
1. Is there a way to have persistent variables? Say a variable that will be held in memory, and which can be accessed by subsequent scripts, without having to write it to a file and re use it later.
2. Is there a way to retrieve results of a command before a pipe, say for example
is there a way that I can get to see the $2 values without writing to a file?
Probably both of these questions can be answered by using different scripts that do more than one function, I just wanted to know if there is a in-built/ default way of doing this.
1. Is there a way to have persistent variables? Say a variable that will be held in memory, and which can be accessed by subsequent scripts, without having to write it to a file and re use it later.
No, there's not a "global" kind of variable. Child processes inherit exported variables from their parents, but it goes no further than that. This is why we have things like /etc/profile.
a) There is a limit to how much stuff you can cram in a single shell variable. On some systems, this can be as small as a screenful or so, so don't go overboard.
b) If you're doing awk | awk | sed | cut | kitchen | sink, you probably could have done that all in one awk and saved yourself a lot of bother and CPU time. You don't need to use awk twice here:
c) That's also a useless use of cat, since awk does not need cat's help to read a file. You can use it as shown above, listing the filename on the end.
To answer question 2, there's actually a few ways to set more than one variable at once. read is a particularly flexible way of doing so. It helps if you know how many are coming, though, or can convince certain ones to come first. Everything you didn't list will get crammed into the last variable you list.
I saved all the numbers in the awk array A so I could print them later. This lets me print the sum first, and then the rest, letting me pick the sum out from the front with read.
I dont get something about sed
If i have a text file inside contain a:a:a:a:a
sed "s/"$title:$author:$price:$qtyAvailable:$qtySold"/"$Ntitle:$author:$price:$qtyAvailable:$qtySold"/"
This work!!
but
If i have a text file inside contain Tom Tom:La La:Di Di :Do Do :De DE
It cannot work... (2 Replies)
I was talking to a coworker and we got into a discussion about the -9. No one knew where the -9 came from and it's not in the man. I suggested that it was like counting to 10 (0-9) and you finally get to the point that that's it, the durned thing is going to die. So how did the -9 come to mean... (3 Replies)
Hello folks,
I have a newly installed Solaris 10 system running on a T6320 blade. I have set up LDM with the intent to move an ldom from another blade to this one. So far, so good.
I had the SAN folks make the LUNs belonging to the ldom visible to my new blade and I can see them, all 4 paths.... (4 Replies)
sorry, just simple question:
how can i do this in bash>
foreach i( 1 2 3 )
sed 's/Hello/Howdy/g' test$i > test$i.new
mv test$i.new test$i
end (6 Replies)
Hi,
I am seeing a curious issue with 'ls' command.
If I open a telnet session of my Solaris box and give "ls".
The output is in 3 columns.
a b c
d e f
g h i
j k l
However, if I give the same command after a couple of hours in the same window, it goes to 6 columns according to the... (7 Replies)
To correct most of the problems with this language, How do I remove the DOS and WORD stuff from it? These come from the fact that it was written on those with a Microsoft supplied platform at the writers request. (1 Reply)
I have a website but I do not for the life of me know how to upload using unix based command lines. Can someone send me a good site that has these commands. That and I am curious to know more about command line based interfacing. :D Curious Dummy (1 Reply)
Dear All
I am curious to know, that in a system compromise, when someone has access to a box, does that individual have access to a shell on the system, i.e. the person is logging into the system using telnet or SSH to remotely access the box?? How does this individual/ hacker access the system. ... (2 Replies)