Sponsored Content
Top Forums Shell Programming and Scripting Need to extract value from a variable Post 302999963 by MadeInGermany on Friday 30th of June 2017 02:42:58 PM
Old 06-30-2017
awk splits on whitespace into fields
Code:
echo "$output" | awk '$1=="bdfo_run_date" {print $2}'

To store this in a variable you can use the ` ` or $( ) (replacing the command by its output)
Code:
output=`echo "$output" | awk '$1=="bdfo_run_date" {print $2}'`

This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract field from variable more efective

Hi, I know that simple way to do this is var=`echo $line | awk '{print $5}'` But maybe there is shorter way to do this ? Also maybe there is some way to assign all fileds from line separated by lets say ":" to some variables instead of var1=`echo $line | awk '{print $1}'` var2=`echo $line... (11 Replies)
Discussion started by: pp56825
11 Replies

2. Shell Programming and Scripting

How to extract variable number from a String

hi,I am new to shell script,I have String,like this: Number of rows exported: 5321 the numbe at end could changing,how can I extract this number and assign it to a variable,then use it later in script. thanks. (19 Replies)
Discussion started by: vitesse
19 Replies

3. UNIX for Dummies Questions & Answers

extract characters from a variable

Hi All, I have scenario as below, I want to cut the characters and store it variable2.. and want to display the variable2.. as shown below... eg: the size may differs , i am show just an example..... numbers are not fixed in variable1..i want to extract characters and... (1 Reply)
Discussion started by: G.K.K
1 Replies

4. Shell Programming and Scripting

Extract Variable and Append it to the file

I have a file named xyz_extract_file_20091201.dat and I need to strip out 20091201 from the file name and append this value as a first field in all the records in the file. Can you please help? Thanks. Eg. Input File: xyz_extract_file_20091201.dat ------------ Campaign1,A2347,Grp_id1... (1 Reply)
Discussion started by: shekharaj
1 Replies

5. UNIX for Dummies Questions & Answers

Using GREP to extract variable following a string

Hello, I'm running calculations and I need to extract a specific number from a output file. So far I've only been able to GREP entire lines containing the string: '1 F=' . I would like to go a step further and extract just the number following '1 F='. The entire line looks like: 1 F=... (10 Replies)
Discussion started by: modey3
10 Replies

6. Shell Programming and Scripting

bash, extract value from the file to the variable

Hi I've got phrases (string) in phrases.txt file and I've got script.sh. How can I draw out the first line from phrases.txt, save it in variable PHRASE and perform the content of script.sh, and then draw out the second line from phrases.txt, save it in the same variable PHRASE and perform the... (4 Replies)
Discussion started by: patrykxes
4 Replies

7. Shell Programming and Scripting

Extract and place in variable

If i wanted to extract the number of collisions from the eth0 section of the ifconfig file and have the output placed in a variable how would i do this? I can get the output displayed using: /sbin/ifconfig eth0 | grep "collisions" What command would i now use to place the output in a... (1 Reply)
Discussion started by: warlock129
1 Replies

8. Shell Programming and Scripting

Extract values from Perl variable

Hi Guys, I am stuck in a problem. I have a variable in Perl script which has value for example X=a-b-c; Now, I want to extract a b c separately into different 3 variables. I know this can be done in shell using awk but Perl behaves a bit different. Can anybody help me on this please?... (3 Replies)
Discussion started by: prashant2507198
3 Replies

9. UNIX for Dummies Questions & Answers

Extract variable name in a string

Hi, I'm doing a script to list all scripts called by a "master" script. But I have an issue as there is some variables in the name of the called scripts. Example: % cat master_script.sh ENVIR=PROD VERSION=1.2 /users/maturix/$ENVIR/program_$VERSION.shI would like my script displays a kind... (7 Replies)
Discussion started by: maturix
7 Replies

10. Shell Programming and Scripting

awk to extract value from column using variable

I am having trouble extracting the value in the columns declared in a variable. I have tried several different variation of awk but both give me the column number and not the actual value of that column. Any suggestions? Neither of the "extract" variables below are performing as desired ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies
basename(1)						      General Commands Manual						       basename(1)

NAME
basename, dirname - extract portions of path names SYNOPSIS
string [suffix] [string] DESCRIPTION
deletes any prefix ending in and the suffix (if present in string) from string, and prints the result on the standard output. If string consists entirely of slash characters, string is set to a single slash character. If there are any trailing slash characters in string, they are removed. If the suffix operand is present but not identical to the characters remaining in string, but it is identical to a suf- fix of the characters remaining in string, the suffix is removed from string. is normally used inside command substitution marks within shell procedures. delivers all but the last level of the path name in string. If string does not contain a directory component, returns indicating the cur- rent working directory. EXTERNAL INFLUENCES
Environment Variables determines the interpretation of string and, in the case of basename, suffix as single and/or multi-byte characters. If is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty vari- able. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, and behave as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. EXAMPLES
The following shell script, invoked with the argument compiles the named file and moves the output to a file named in the current direc- tory: The following example sets the shell variable to RETURN VALUE
and return one of the following values: Successful completion. Incorrect number of command-line arguments. SEE ALSO
expr(1), sh(1). STANDARDS CONFORMANCE
basename(1)
All times are GMT -4. The time now is 11:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy