I save the result in a variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers I save the result in a variable
# 8  
Old 09-12-2014
Quote:
Originally Posted by RavinderSingh13
Hello tricampeon81,

you can use the following command also for same.

Code:
 salida=`echo "prueba.txt" | awk '{gsub(/\..*/,X,$0);print "result= " $0}'`

Output will be as follows.

Code:
echo $salida
result= prueba

Thanks,
R. Singh

Will it work if s= `awk '{gsub(/\..*/,X,$0);print "result= " $0}'` ?

Last edited by Don Cragun; 09-12-2014 at 03:07 AM.. Reason: Add ICODE tags.
# 9  
Old 09-12-2014
Quote:
Originally Posted by santoshdrkr
Will it work if s= `awk '{gsub(/\..*/,X,$0);print "result= " $0}'` ?
That depends on what you are trying to do.

If you are trying to run the commands named by stripping everything following the 1st period on every line found until awk hits EOF while reading standard input for your shell script with the environment variable s set to an empty string for the 1st command executed and the remaining commands executed without s in their environment then, yes, it will work. Is that what you are trying to do?

Last edited by Don Cragun; 09-13-2014 at 11:32 PM.. Reason: Fix auto spell-check fix error.
This User Gave Thanks to Don Cragun For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to save a data of a file into a variable?

My requirement is to read a column data from a file & save it in a variable for each row & process it. I am using the below code- Leadlines="$TGTFILE/Error.txt">>$log_file while read line do id = ` echo $line | cut -d "," -f1 ` email = ` echo $line | cut -d "," -f2 ` ----------- done My... (2 Replies)
Discussion started by: saga20
2 Replies

2. Shell Programming and Scripting

Save result to a text file

Currently I have a perl code to combine two different files. #! /usr/bin/perl -w use strict; open FP1,"A.txt"; open FP2,"B.txt"; my ($l1,$l2); while(1) { $l1=<FP1>; chomp $l1; $l2=<FP2>; chomp $l2; last unless(defined $l1 or defined $l2); print "$l1 $l2\n"; } close FP2;... (4 Replies)
Discussion started by: Tzeronone
4 Replies

3. UNIX for Dummies Questions & Answers

Solved: how to save an output to a variable

i want to save the output of /scripts/whoowns domain.com to a username like $user = /scripts/whoowns domain.com but I'm not sure how to do that This is inside a bash script how can I get the output of /scripts/whoowns then save that to a variable? thanks! ---------- Post updated at... (0 Replies)
Discussion started by: vanessafan99
0 Replies

4. Shell Programming and Scripting

awk and save result on a different file

Hi, If I type: ls -l *txt | awk '{print $8}' I get the file listing if I am in the directory. If I try to do the same from a job flow, doing also other things, I can't do ls -l directory/*txt | awk '{print $8}' > directory/result.txt or echo ls -l directory/*txt | awk '{print... (8 Replies)
Discussion started by: essemario
8 Replies

5. Shell Programming and Scripting

how to save an output of a command in a variable

Hi, in shell script, i have the command swstart -p which returns an output. i want to store the output of this command into a variable. how i can do that excerpt from the script #!/usr/bin/ksh # # # # Program: swstart -p # # Description: Starts the sentinels on Slave server ... (4 Replies)
Discussion started by: lookinginfo
4 Replies

6. Shell Programming and Scripting

Save output in a variable

Hi, I have a 3rd party tool on Solaris 8. I am running it thorugh my script but I am not able to capture its output into a variable. Like, I tried, but did not work. output=`/usr/bin/myTool` echo $output Also, I tried saving in a file but when I run, output is always shown on the... (19 Replies)
Discussion started by: angshuman_ag
19 Replies

7. Shell Programming and Scripting

Way to save output result of a program into another new file...

Does anybody know any alternative way to save output result of a program into another new file? I got try the command below: program_used input_file > new_output_file program_used input_file >> new_output_file Unfortunately, both the ">" and ">>" is not work at this case to save the output... (6 Replies)
Discussion started by: patrick87
6 Replies

8. Shell Programming and Scripting

"Time" command and save result in a file.txt

Hi, I'am using "time" to check execution time of some script. Is there any possibility to save time command result into a file ? (2 Replies)
Discussion started by: Physix
2 Replies

9. Shell Programming and Scripting

save the HTML result

Hi all, I am displaying my result in HTML format using tables. I want to save the results in file in the same format along with the table only. How do i do that in perl? I have attached the table structure . I want to save like that itself . with regards (2 Replies)
Discussion started by: vanitham
2 Replies

10. UNIX for Dummies Questions & Answers

Save contents of a Variable

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)
Discussion started by: carl_vieyra
1 Replies
Login or Register to Ask a Question