Transfer output to empty file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Transfer output to empty file?
# 1  
Old 09-22-2010
Transfer output to empty file?

Hi all,

I want transfer the echo data into file.txt.how?
echo " $dir $group " >> ${file.txt}

---------- Post updated at 04:11 PM ---------- Previous update was at 03:10 PM ----------

anybody can help ?
i mean in script output like
echo " hello"

i want transfer that output to file.txt.
# 2  
Old 09-22-2010
It is not very clear what you are asking for here, so I will take a guess..

To echo simple variables into files use something like:
Code:
echo "$dir $group" >> file.txt

However if you want to echo variables into a filename that is held in a variable:
Code:
fname="file.txt"
echo "$dir $group" >> $fname

Please note that ">>" appends to the file. If you want to create the file new each time just use one redirect ">"

I would recommend searching for "simple shell script tutorial" on your favourite search engine.

I hope this helps.
# 3  
Old 09-22-2010
hi citaylor,

then i need to set as variable in my script?
# 4  
Old 09-22-2010
The first example is an example of a hard-coded file name, ie "file.txt".
The second example is an example of a file name kept in a variable that is usually set in the script.
Another example is:
Code:
#!/bin/sh
echo "$dir $group" >> $1

"$1" is special, it means use the first argument passed to the shell script, so if you then ran the shell script, for example "./script foo.txt" then the output would be stored in foo.txt
# 5  
Old 09-22-2010
Hi

if i want get the output of $fname ?how i going to type the code?
because i type echo $fname nothing come out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Parsing null or empty output

I am working an some if then statements for a script. I want to be able to check for alpha characters or empty out put then exit out. if ]]; echo "Serial Number Invaild" then exit 3; How do I account if the output is empty or null in this in this statement. Many thanks (6 Replies)
Discussion started by: andysensible
6 Replies

2. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

awk runs but output is empty

The awk below runs, however the output file is 0 bytes. It is basically matching input files that are 21 - 259 records to a file of 11,137,660 records. Basically, what it does is use the input files of which there are 4 to search and match in a large 11,000,000 record file and output the... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Transfer output of a proprietary command to a file

Hi Guys, My problem looks simple. I have a software-proprietary command (not linux) that provides an output, let's say 200 lines. Unfortunately the dumb coders of the software did not include the option ">" or ">>" which allows to transfer output to a file, so I need a way to do that using some... (5 Replies)
Discussion started by: liviusbr
5 Replies

5. Shell Programming and Scripting

Sent output to email and empty folder at same time

Hi all, i want to sent output to email and folder at same time. This is my code : echo "Hello" | mailx -s "${SUBJECT}" "${email_add}" >> ${file} I only can sent output to my email but cannot sent to my empty folder....can i know how to done it? (1 Reply)
Discussion started by: proghack
1 Replies

6. Shell Programming and Scripting

Output only non-empty arguments

Hello, I am VERY new to shell scripting here, so please go easy. I have an assignment that requires creating a script using bash shell, outputting all command line arguments that are not empty ones such as " ", and showing total number of arguments. I know how to show the total with $# and all... (6 Replies)
Discussion started by: moderwarfare
6 Replies

7. Shell Programming and Scripting

empty option output error

I have a script (multirun.sh) which launches the program bsim_em.x or bsim_es.x depending on the value entered from the screen: > multirun.sh 1 (executes bsim_em.x) > multirun.sh 2 (executes bsim_es.x) which, simplifying, I do with the following lines in the multirun.sh script: if ... (3 Replies)
Discussion started by: josegr
3 Replies

8. Shell Programming and Scripting

Change output if file is empty

I'm very new to writing scripts, so here is my problem...I have the following code already written (in perl) system "rm file2"; open(FILE2, ">file2"); open(MYINPUTFILE, "file"); while(<MYINPUTFILE>) { my($line) = $_; chomp($line); print file2 "$line\n"; print... (2 Replies)
Discussion started by: ddrew78
2 Replies

9. UNIX for Dummies Questions & Answers

Getting same exit status for empty and non empty file

Hi All, I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both. The value of $? is coming 0 in if part also and else part too. #!/bin/ksh if ]; then echo "data" # exit 0 echo "$?" else... (4 Replies)
Discussion started by: mavesum
4 Replies

10. UNIX for Dummies Questions & Answers

The output file is empty. Please Help

Dear all, Currently I writing a ksh script to perform some sql query. I already pipe results in a output file. But when I checked it, the output file is empty. Below is part of the script that I wrote: ------------------------------------------------------------------------ function... (4 Replies)
Discussion started by: balzzz
4 Replies
Login or Register to Ask a Question