Place the results of a CUT command into a variable


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Place the results of a CUT command into a variable
# 1  
Old 03-07-2014
Place the results of a CUT command into a variable

I am being passed a file in UNIX, ie: variable.txt

I need to extract the first part of the file content, up to the period, content ie: common_dir.second_output

Code:
cut -d'.' -f1 /content/stores/variable.txt



I then need to utilize the results to create a variable ($1), and test on that result. ie: $1 = common_dir

Code:
 if test -d /var/mqsi/deploy/$1
            then cd /var/mqsi/deploy && rm -Rf $1
             echo /var/mqsi/deploy/$1 deleted.
 else
             echo /var/mqsi/deploy/$1 does not exist.
 fi



How do I pipe or place the results of the cut command into the variable $1, so $1 = common_dir

Or what is the best command to accomplish this?
# 2  
Old 03-07-2014
Is this a homework assignment?
# 3  
Old 03-07-2014
No, its not a homework assignment

This is a small part, and the easiest part, of fully automating a BAR File deployment.

The script I am writing will access a product called REMEDY to extract a deployment ticket, it will then automatically extract the code from a software repository called StarTeam, it will then FTP the code to Servers and perform an automated deployment of a BAR file.

The file that will be passed will contain much more information than what was indicating, including (but not limited to) the StarTeam project name, View Labels, BAR and TAR files to be deployed, Target Servers and Directories, and other information.

The information that I provided was a small part of the process and only involved with verifying and removal of the old Execution Group Directory.
# 4  
Old 03-07-2014
If the code you listed previously:
Code:
 if test -d /var/mqsi/deploy/$1
            then cd /var/mqsi/deploy && rm -Rf $1
             echo /var/mqsi/deploy/$1 deleted.
 else
             echo /var/mqsi/deploy/$1 does not exist.
 fi

is in a separate script, you can invoke it using:
Code:
script_name $(cut -d'.' -f1 /content/stores/variable.txt)

which will set $1 in that script to the string returned by cut.

Otherwise, to set $1 in your current shell execution environment, you could use:
Code:
set -- $(cut -d'.' -f1 /content/stores/variable.txt)

# 5  
Old 03-07-2014
Thanks...

Thanks, I will try this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I want to add a variable for the results from the formula of one variable and results of another var

Good morning all, This is the file name in question OD_Orders_2019-02-19.csv I am trying to create a bash script to read into files with yesterdays date on the file name while retaining the rest of the files name. I would like for $y to equal, the name of the file with a formula output with... (2 Replies)
Discussion started by: Ibrahim A
2 Replies

2. Shell Programming and Scripting

Use cut output as variable piped awk command

Hi, I would like use the output of my cut command as a variable in my following awk command. Here's what I've written. cut -f1 info.txt | awk -v i=xargs -F'' '{if($6 == $i) print $20}' summary.txt Where obviously the 'xargs' doesn't do what I want. How can I pass my cut result to my awk... (3 Replies)
Discussion started by: heyooo
3 Replies

3. UNIX for Beginners Questions & Answers

Results of ldapsearch piped to grep are cut off

ldapsearch -x -LLL -E pr=200/noprompt -h abc-loc.somecompany.com -D "account@somecompany.com" -w password -b "cn=groupname,ou=Resource,ou=groups,dc=abc,dc=somecompany,dc=com" | grep member Results are: member: CN=Hanson\, Joe,OU=End Users,OU=Accounts,DC=abc,DC=somecompany,DC=com member:... (3 Replies)
Discussion started by: who10
3 Replies

4. Shell Programming and Scripting

Storing command output in a variable and using cut/awk

Hi, My aim is to get the md5 hash of a file and store it in a variable. var1="md5sum file1" $var1 The above outputs fine but also contains the filename, so somthing like this 243ASsf25 file1 i just need to get the first part and put it into a variable. var1="md5sum file1"... (5 Replies)
Discussion started by: JustALol
5 Replies

5. Shell Programming and Scripting

sed and cut command in variable

hi, i want to remove 12 and 13 column from psv files and dump them in new folder ls -ltr *GTDA_Dly_Pmix_*.psv>filename.xls var1=`cat filename.xls` for i in $var1 do var3=`echo "$i" |cut -d '|' -f12,13 |sort -u` sed -e 's/"|$var3"//g... (2 Replies)
Discussion started by: renuk
2 Replies

6. Shell Programming and Scripting

Cut text file in place

I have a file that i want to take only the first part of it and discard the rest, to be accurate,I need the first 137097 lines but I cant use split because I dont have enough space on my disck. I need sth to cut the file in its place (3 Replies)
Discussion started by: Heidi Heweidy
3 Replies

7. Shell Programming and Scripting

Place 'find' results within TeX command

Hi, In an effort to collect all my .java-files and place them in a LaTeXfile (using the listings environment of latex), i tried to use ex. So what i have now is: find . -name "*\.java" > latex ex latex <<HERE %s/\(.*\)/\\lstinputlisting{\1} wq HERE So i try to escape the '\' with... (1 Reply)
Discussion started by: HannesBBR
1 Replies

8. 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

9. UNIX for Dummies Questions & Answers

Cut Command value assign to variable

Hi, I am new to UNIX Scripting. I have been trying to use the CUT command to retrieve part of the header from a file and assign it to a variable. I have tried searching a lot, but I am still unsuccessful. Sample Header: HJAN BALANCE 20090616 I need to retrieve the date here, which always... (10 Replies)
Discussion started by: ragz_82
10 Replies

10. UNIX for Dummies Questions & Answers

Setting the Results of a Command to a Variable

Hi, Hi, I run the command: hostname to get the host back from the server: db201 Now, I need to take that result and set it to a variable. Can anyone help me with this?? I need to be able to use the same script on multiple servers so I do not want to hardcode the hostname result into... (1 Reply)
Discussion started by: stky13
1 Replies
Login or Register to Ask a Question