For ex:
Def var l_output as character.
Unix silent value(file filename | awk '{print $2}').
Output will be like format of filename i.e ascii, so now I need to return this value in a variable l_output??
Pls someone help me to sort this out. Thanks
Please use the INPUT THROUGH VALUE (your Unix statement).
This opens a stream for the output of the OS Command. Then
REPEAT:
IMPORT l_output.
MESSAGE l_output.
END.
Related
I am trying to read a parameter from the URL, i am able to read for single line but i don't know how to loop in awk, can someone help?
i have file with 1000+ entries like
http://projectreporter.nih.gov/project_info_details.cfm?aid=7714687&icde=0
http://projectreporter.nih.gov/project_info_description.cfm?aid=7896503&icde=0
http://projectreporter.nih.gov/project_info_details.cfm?aid=7895320&icde=0
http://projectreporter.nih.gov/project_info_details.cfm?aid=2675186&icde=9195637
i am trying to only retrive "aid=xxxxxxx", i used the following command to do it and i get the "aid" for the last line
awk '{match($0,"aid=([^ &]+)",a)}END{print a[1]}' file1.txt > outputFile.txt
how to do the same in a loop so i can get all the occurrence?
any help would be appreciated
This should work a little fine tuning for your attempted code.
awk 'match($0,/aid[^&]*/){print substr($0,RSTART,RLENGTH)}' Input_file
In case your single line can have multiple occurrences of aid and you want to print all then try following.
awk '
{
while(match($0,/aid[^&]*/)){
print substr($0,RSTART,RLENGTH)
$0=substr($0,RSTART+RLENGTH)
}
}
' Input_file
We are using Oracle Apps where we also develop programs using UNIX. In our Oracle Apps UNIX program, while running a program, we will pass parameters and the parameter values will be stored in $1 value. And this $1 will also contain other information like instance, what is program id, program ran user name and user id etc., as below
XX_VENDOR_ACH_HOST FCP_REQID=9946271 FCP_LOGIN="APPS/trn12fnd" FCP_USERID=127 FCP_USERNAME="USERNAME" FCP_PRINTER="noprint" FCP_SAVE_OUT=Y FCP_NUM_COPIES=0 "TEST Pay Batch 021120-c"
here, TEST Pay Batch 021120-c is the only parameter value. Now, I need to fetch this parameter value. So, I wrote the command as below
echo $1 | cut -d" " -f9 | sed 's/"//g'
But, it is just printing the word TEST not the complete value. Can anyone please help me with the complete command to fetch TEST Pay Batch 021120-c
Regards,
Srivathsava
Assuming;
The parameter value is enclosed with double-quotes
The parameter value is located at the end of $1
then how about;
echo "$1" | sed 's/.*"\([^"]\+\)"$/\1/'
which outputs:
TEST Pay Batch 021120-c
If my assumptions are incorrect and if the parameter value string has
some distinct characteristics (e.g. it starts with TEST Pay Batch),
please let me know. Then I'll tweak the regex to extract the parameter value.
Assuming the parameter value is located at the end of $1 something like can do the work:
echo $1|awk -F\" '{print $(NF-1)}'
How can I call an awk script from an awk script and assign the output of the first to a variable in the second?
I have an awk script that reads files each night, checks each line of data and writes to a new file. I need to add in some additional formatting to one of the fields. I already have a standalone awk script that does the formatting so all I need to do is call this awk script for the appropriate fields and assign the value that is normally printed to a variable.
To put it in context, the following prints the required formatting to the screen (because that's what title_case.awk does), but I can’t use the value for further processing.
print old_name | ("/production/bin/title_case.awk")
so I need something like the following:
new_name = 'old_name | ("/production/bin/title_case.awk")
Thanks,
Ger
You can try using getline into a variable ( http://www.gnu.org/software/gawk/manual/gawk.html#Getline_002fVariable_002fPipe )
("/production/bin/title_case.awk "old_name) | getline new_name
All,
I want to execute a unix statement in expect script.The unix statement outputs rsize value for a process. I haven't programmed in expect before.
This is my code:
#!/usr/bin/expect
set some_host "some host"
set Mycmd "top -l 1 -stats pid,rsize,command | grep Process_Name| awk '{print \$2};'"
spawn telnet localhost $some_host
expect "login:"
send "myDevice\r"
expect "Password:"
send "$password\r"
expect "\$"
send "$Mycmd\r"
When I execute this, I don't get any output. What's the correct syntax to execute the unix statement? How do I get this to work so that I get the correct rsize value as the output?
Always a good idea to try to escape with ascii, try \0442 for \$2 or try something like \\$2
.Also you can debug the script to find why you have no output if you insert 'exp_internal 1' without quotes at the second line.
Is it possible to get the output without having to add the "interact" statement
Yes, it is. Other statements which wait for the output will also do; you could add e. g.
expect -re "\n\[0-9]+"
to the end of your script.
I have a dat file with some data in it seperated by '|' character.
I want to read each line and take out 5th and 6th column data( date format) from here and then validate the date using unix. I am new to unix . Please let me know how to do it.
Try using an awk script (http://www.manpagez.com/man/1/awk/) for parsing files. Something like
awk -F\| '{print $5, $6}' test.dat
This can then be extended to perform date validation, depending on what validation needs are. For example - http://unix.derkeiler.com/Newsgroups/comp.unix.shell/2003-08/1340.html seems to perform a reasonable amount of validation.