Evaluation syntax in Unix commands


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Evaluation syntax in Unix commands
# 1  
Old 03-01-2011
Evaluation syntax in Unix commands

I know this should be simple, but sorry I am fairly new to UNIX and can't find the syntax to make this work.

I have the following two commands in a script:

Code:
x=`expr $(head -1 filename.ext | cut -c16 | grep [A-Z] | wc -l) + 16`
del=`head -1 filename.ext | cut -c$x`

This works fine as I expect it to. But I want to combine it into one command. Essentially I just want the entire expression that I am assigning to x in the first command to be evaluated at the end of the second command as my argument to the -c attribute of the cut command. But I've tried every way I can to get it to evaluate properly and can't get it.

Thanks for any help.

Last edited by Franklin52; 03-01-2011 at 03:42 PM.. Reason: Please use code tags, thank you
# 2  
Old 03-01-2011
not tested.....
Code:
del=$(head -1 filename.ext | cut -c $(expr $(head -1 filename.ext | cut -c16 | grep [A-Z] | wc -l) + 16))

# 3  
Old 03-01-2011
Tested now... and it works.

Thought I tried that as I tried most every similar combination with no luck. Must have have missed that one.

Thanks for the quick (and correct) response.

DJR
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Evaluation of test command

Could somebody please explain to me why and how the highlighted line(s) (?) of code puts the "test" evaluation into "result" and then to $enable_static ? Or does not ? I did comment out the original code and changed it to what I feel is less cryptic , but the "result" is still wrong =... (3 Replies)
Discussion started by: anne
3 Replies

2. Shell Programming and Scripting

Help understanding evaluation order

I have made a simple script to find all programs that use a tcp wrapper, it will supply a reasonable default for my system if none is given. After some digging I realized that the expansion operators pass their default return value single quoted (according to bash -x trace). I have wildcard... (2 Replies)
Discussion started by: phuongnguyen
2 Replies

3. Shell Programming and Scripting

Help on grep syntax in UNIX

Dear Team /app/Appln/logs/ echo Session used server are 'grep -i pid|grep -i session | cut -d'.' -f1 | awk '{print $9}' | sort | uniq' Output - lxserver01 lxserver02 lxserver03 When I grep session pid in logs server details I can see above distinct server details but I... (6 Replies)
Discussion started by: skp
6 Replies

4. Shell Programming and Scripting

Special IF construct syntax in UNIX

Hi, I don't understand && and || in this context. I thought && is for logical 'AND' and || is for logical 'OR'. && echo "Not empty" || echo "Empty" Please help Thank You (5 Replies)
Discussion started by: TomG
5 Replies

5. Cybersecurity

iptables latency evaluation

Hello guys, I'm actually working on my master thesis which has for subject the evaluation of virtual firewall in a cloud environment. To do so, I installed my own cloud using OpenNebula (as a frontend) and Xen (as a Node) on two different machines. The Xen machine is my virtual firewall thanks... (2 Replies)
Discussion started by: Slaughterman
2 Replies

6. UNIX for Dummies Questions & Answers

cp command evaluation

Hi all! I'm writting one script to copy a file in various folders, but there are 2 things to validate. First that the folder where i'll be cpying exists, and second that i have permissions to copy the file in it. so far i have found the way to validate the folder exists, but when trying to... (6 Replies)
Discussion started by: feliperivera
6 Replies

7. UNIX for Dummies Questions & Answers

Syntax for own UNIX command

hi All, how can i make my own commamnds for unix shell scripts. lets xmple.. 1-i want to use "down arrow key" for previous runned unix commands. then how to acheive it. 2-Generally TAB --- complete filename or command up to the point of uniqueness ..but here its not working .. I m new to... (1 Reply)
Discussion started by: pradeepcarya
1 Replies

8. Shell Programming and Scripting

Unix Script Syntax

Hi Josh Hope you are doing fine..I have a small requirement but unable to get a syntax for it. Here is how it is. There is a Server say ABC.From another Server i need to get records from Server ABC. Now logic is written as follows. It creates a file as per sysdate and append the... (1 Reply)
Discussion started by: mmaller0319
1 Replies

9. UNIX for Dummies Questions & Answers

Maingrame to UNIX sending UNIX commands

I want to know if there is a way to send unix commands thru FTP from a mainframe to kick off Autosys Jobs. I just need to send a command from the mainframe to UNIX and have UNIX execute that command. (2 Replies)
Discussion started by: skammer
2 Replies
Login or Register to Ask a Question