Accept data from file or stdin in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accept data from file or stdin in script
# 1  
Old 06-21-2017
Accept data from file or stdin in script

I have a script that looks like this:
Code:
sed -f myfile.sed $1 > $1.out

called myscript and would like to change it so the parameter isn't necessary:
Code:
ls *.idx | myscript | xargs some_command

What do I need to add so it can run either way?

TIA

---------- Post updated at 09:41 AM ---------- Previous update was at 09:33 AM ----------

Never mind, asked for help too soon. After
Code:
if [ $# -eq 0 ]
  then

I added the same sed command removing everything on the line starting with the first $1.
# 2  
Old 06-22-2017
Thanks for the update.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

Oracle/SQLPlus help - ksh Script calling .sql file not 'pausing' at ACCEPT, can't figure out why

Hi, I am trying to write a script that calls an Oracle SQL file who in turns call another SQL file. This same SQL file has to be run against the same database but using different username and password at each loop. The first SQL file is basically a connection test and it is supposed to sort... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. UNIX for Beginners Questions & Answers

How to use stdin as argument for script?

Say I had an extremely simple script called testScript.sh: #!/bin/sh echo $1 and I invoked it as: source testScript.sh <<< x or source testScript.sh <<< inputFile.txt When I do the above the values don't appear in the echo statement, and I know that is because in the echo... (5 Replies)
Discussion started by: steezuschrist96
5 Replies

4. UNIX for Dummies Questions & Answers

UNIX script can accept 1 to n parameters

Just for my leaning purpose, I appreciate if someone answer my question: A UNIX script can accept 1 to n parameters. For each of these parameters, write out the parameter id number and its value. (1 Reply)
Discussion started by: shumail
1 Replies

5. Shell Programming and Scripting

Suplying stdin input within script

Hi , I have script in that , i uninstall rpm using rpm -ef $rc1 now my query is rpm -ef is asking user input DO YOU Want To continue (YES/NO) for each uninstalltion. now i want to supply YES variable when it asks for above statement . so that i dont have to give user input from... (4 Replies)
Discussion started by: raghavendra.nsn
4 Replies

6. UNIX for Dummies Questions & Answers

script unix which accept two arguments

does anyone can help me with this homework, please..I am beginner in linux and I don't how to do it :( Create a script scanner.sh which will accept two arguments: the first argument is the DNS name or the IP address of a system, or a network address or an IP range, the second argument is... (1 Reply)
Discussion started by: gennyy
1 Replies

7. Shell Programming and Scripting

ksh script that will accept arguments

Hi, I am not very skilled using ksh scripts. How do I create a ksh script that will accept arguments and use them in the script ? I need to make this: Run this command with this argument: ./mykshprogram.ksh madsen and sometimes I need to do this: Run the ksh again with 2... (3 Replies)
Discussion started by: hasselhaven
3 Replies

8. Shell Programming and Scripting

Shell script regex help: accept only 3 file extensions

This regex is supposed to accept files with extensions 270, 276, and "txt" only. Everything else should be discarded. This is what I have. I'll spare you the rest of the code. ext =".\$" #ext =".\$" #ext =".\$" #ext =".\$" for xfile in `ls $dir | grep "$ext" | xargs`; do... (9 Replies)
Discussion started by: grep01
9 Replies
Login or Register to Ask a Question