Hello, All. This is my first post here, and I expect that the answer is simple, but I can't find it. Might be the way I'm searching. I'm fairly new to Unix/Linux, and I'm writing a Korn Shell Script. I am trying to provide a value that is already in a variable to awk so that awk can pull out the second column.
An example of what I'm trying is here:
The line should be comma-separated, and I'm trying to pull out the second entry, but all this does is print out the contents of $g, which doesn't do me any good.
Once I can pull out the second entry, I plan on using it for some decision making, but that's secondary right now.
awk is its own entire programming language, incidentally. If all you wanted to do was to extract the second column for further processing, that further processing could probably be done inside awk too.
Or if you wanted to keep it in shell, you can do this wholly in shell without using awk at all:
IFS is a special variable controlling what the shell does variable splitting on. Its value is only temporarily changed here, while read is being run.
Thanks, Corona. As I said, I'm relatively new to Unix, and I'm still learning what can and can't be done, and the best way to do things. I'm still reading up on awk, and learning how to use it, but as a programming language in itself, it's a lot to take in.
I'm trying your solution now, and I'll reply the status when it's done. The script takes a bit of time to run.
---------- Post updated at 02:30 PM ---------- Previous update was at 12:57 PM ----------
Thanks again, Corona. I reworked my script using just awk, and removing the while loop, and it worked as I'd hoped.
i want to reduce the OPTIONS variable which is a list of email addresses to just the unique entries. The following works, but, i would like to accomplish it without using the temporary file (dest.txt)
$echo $OPTIONS
a b c A B D ... (5 Replies)
Hi All,
I was trying a shell script. I was unable to store file contents to a variable in the script. I have tried the below but unable to do it.
Input = `cat /path/op.diary`
Input = $(<op.diary)
I am using ksh shell. I want to store the 'op.diary' file contents to the variable 'Input'... (12 Replies)
Hi one of the output of the command is as below
# sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/'
Resource List : <br>
*************************** 1. row ***************************<br>
... (2 Replies)
A question to the awk pundits:
I was thinking about composing a regex in a variable and then use its contents like $0 ~ var instead of $0 ~ /r/. Sort of indirection. Did someone run into this? Is it possible at all? (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I have to read the contents of each field of a file creating user accounts.
The file will be of format :
... (6 Replies)
Hello All,
I've written a script to collect all audit logs files; now i want to see only the files from it which contains certain x tablenames. I've stored all the tablenames in a log file and using it through variable in a script (ex:below)
$ more tablenames.log (this is just a samle... (2 Replies)
Hi ,
I have
#echo $var1
#hdisk2 hdisk3 hdisk0 hdisk2
Now I need to remove duplicate entries from this . ie. after sorting it should only have
hdisk2 hdisk3 hdisk0 .
I can have these values in a array as well . I understand we can use sort -u to remove the duplicates in a... (2 Replies)
I want to save the contents of a variable to a file. How can that be achieved?
I have tried with:
echo $varname > textfile.txt
but for some reason it does not print anything. (1 Reply)
hi all,
i'm new to shell scripting, so i'm not sure how to work this. Is it possible to read in the contents of a variable and add it to a command? for example:
------------------------
#!/bin/sh
set example = -dfr
rm ${example}
------------------------
when i run the script, i want... (2 Replies)