Pipe with extra argument


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pipe with extra argument
# 1  
Old 06-21-2011
Pipe with extra argument

Hi,

I want to pipe an output to another command with an extra argument. Can anyone tell me how is it possible?

Eg:
Code:
$date +%d

will give the current date. I want to add 1 to it and give it as argument to my calc command.
Code:
$calc "todays date" + 1

Basically i want to diplay tomorrows date. Any method for that?

I tried doing this
Code:
$ calc | date +%d

The calc command is nothing but the following:
Code:
#!/bin/bash
echo "scale=4; $1" | bc ;exit


Last edited by Franklin52; 06-21-2011 at 03:03 AM.. Reason: Please use code tags for code and data samples
# 2  
Old 06-21-2011
do you have gnu date ?

execute the below commands and check

Code:
 
date --date='tomorrow' +%d
date --date='1 day' +%d

# 3  
Old 06-21-2011
I am using Sun OS.
Those commands dont work. It says illegal options
# 4  
Old 06-21-2011
Then you are out of luck. Can you use Perl or Python (and what versions)?
# 5  
Old 06-21-2011
Hi
Check this perderabo's date script

Guru.
# 6  
Old 06-21-2011
Code:
 
bash-3.00$ perl -e 'print scalar(localtime(time + 86400)), "\n"'
Wed Jun 22 07:08:43 2011
bash-3.00$ date
Tue Jun 21 07:08:45 BST 2011
bash-3.00$

# 7  
Old 06-21-2011
@itkamaraj
That was awesome. It works fine.
Can you tell me how to extract only the day or month from it?
Like
Code:
$date +%d

will give you only the current day.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

2. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

3. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

4. Shell Programming and Scripting

Replace pipe with Broken Pipe

Hi All , Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies

5. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

6. Shell Programming and Scripting

removing extra double quotes between pipe dilimeter

I have a flat file sample like this - "COURSE"|"ddddd " " dddd"|"sssddd sdsdsdsdx" dddddddd ffffff "aaaaa" dddddddd ffffff sdsdsd"|"xxxxxxx"| "COURSE"|"ffff " " bbbb"|"lllll"| The delimiter is pipe character (|) and the text are enclosed in double quotes... (5 Replies)
Discussion started by: vishalzone
5 Replies

7. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

8. UNIX for Dummies Questions & Answers

How to find the last argument in a argument line?

How to find the last argument in a argument line? (4 Replies)
Discussion started by: nehagupta2008
4 Replies

9. UNIX for Dummies Questions & Answers

pipe output to script as command line argument

i want to redirect output of one command as the command line argument of another script for example, say i would run this command: find . -xdev -type f -size +4096 -exec ls -al {} \; i wan to be able to do something like: echo +4096 | find . -xdev -type f -size ****** -exec... (3 Replies)
Discussion started by: IMTheNachoMan
3 Replies

10. UNIX for Dummies Questions & Answers

newbe looking for extra help

Hi all, i'm new here and to Unix and have a question about more help then I am getting. I live basically in Portland, OR and am attending college and have to take some Unix classes for my degree. Well class is fine and the help from the instructor is ok but I would like to receive more help then... (5 Replies)
Discussion started by: lisdog58
5 Replies
Login or Register to Ask a Question