Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-04-2004, 07:26 AM   #1
LQ Newbie
Registered: Dec 2004
Posts: 6

Rep: Reputation: 0
Talking shell scripts and varibales

Hi i wanna do something very easy. something like this.

num='grep -w "+ 4 0" out.txt | awk '{print $4;}''

basically i want to pass the output of this to num. and as it is awk prints to the screen. can i stop awk printingin its output to thje screen. i think what i want to do involves getline aswell but i cant seem to get this write.

also to finish off once i have num how could i append num to another file called 1.txt. when i say append i mean stick it on at the end. this is basic i know but im struggling to do it. this is a simplified version of what im doing but i should be able to do what i want to do if i get an answer here.

Old 12-04-2004, 09:31 AM   #2
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
num=`grep -w "+ 4 0" out.txt | awk '{print $4;}'`
echo $num >> 1.txt

So its backtick not single quotes there .

And awk will not print it to screen

Old 12-04-2004, 10:24 AM   #3
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 25, 26, RHL 5.2
Posts: 560

Rep: Reputation: 56
Use I/O redirection to send output to a file rather than standard out. If you want all the output from your script to go to a file you would type scriptname > outfile at the command line. The > sign redirects the output to the file outfile. To append output to a file use >>.

You can also use this technique inside your script to direct output to multiple files. For example, if I wanted a logfile with execution status and an output file my script might look something like.

# Writing to files example


ps -aux > out.txt
let rs=$?
printf "Job was a " > log.txt
if [ $rs = 0 ]
   printf "%s\n" $SUCCESS >> log.txt
   printf "%s\n" $FAILURE >> log.txt
Old 12-04-2004, 10:25 AM   #4
LQ Newbie
Registered: Dec 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks zulfilee
im nearly finsihed my script now. just one more thing if you dont mind

if i want to do the following

echo ("$ns at" & $time & "$udp1 send [CONST_SIP_SIZE]") >> UDP.tcl
echo "$ns at [CONST_FINISH_TIME] "FINISH"" >> UDP.tcl
echo "$ns run" >> UDP.tcl

where ns is not a variable but the actual text i want to append. time is a variable and $udp is not a variable but actual text. and i want FINISH to be "FINISH" in UDP.tcl
Old 12-08-2004, 09:00 AM   #5
Registered: Nov 2004
Location: India
Distribution: RedHat, PCQLinux, Fedora
Posts: 95

Rep: Reputation: 15
echo ("$ns at" & $time & \"\$udp1 send [CONST_SIP_SIZE]") >> UDP.tcl
echo "$ns at [CONST_FINISH_TIME] \"FINISH\"" >> UDP.tcl
echo "$ns run" >> UDP.tcl

\ is the escape charater you gotta use


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
I Need shell scripts flyyy_82 Linux - Security 1 01-27-2005 05:05 PM
shell scripts rocketgo Linux - General 10 12-01-2003 06:20 AM
need help on shell scripts!!! krcool32 Programming 5 04-28-2003 04:08 PM
Shell scripts j0hn0n1 Linux - Software 1 01-03-2003 04:11 PM
shell scripts gui10 Programming 10 10-28-2001 03:46 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration