Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 30 Aug 2014, 00:34
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
[Solved ] - echo command to file ?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
stu90


Joined: 25 Feb 2010
Posts: 1401
Location: England. Dell Inspiron 1501. Dpup

PostPosted: Tue 29 Mar 2011, 14:16    Post subject:  [Solved ] - echo command to file ?  

Hello,

I am trying to echo a command to a file, the command is:

echo $(awk 'NR==7 { print $4,$2 }' /proc/cpuinfo)

What i would like to do is echo the actual command its self to the file and not the command output.

using this command:

echo 'echo $(awk 'NR==7 { print $4,$2 }' /proc/cpuinfo)' > /root/file

results in the /root/file entry

echo $(awk NR==7 { print , } /proc/cpuinfo)

which has several missing parts, any ideas ?

thanks.

Last edited by stu90 on Wed 30 Mar 2011, 12:49; edited 2 times in total
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Tue 29 Mar 2011, 15:36    Post subject: echo command to file
Subject description: use "
 

tried
Code:
# echo 'echo $(awk "NR==7 { print $4,$2 }" /proc/cpuinfo)' > /root/file

results in:

echo $(awk "NR==7 { print $4,$2 }" /proc/cpuinfo)

Hope that helps
Back to top
View user's profile Send private message 
stu90


Joined: 25 Feb 2010
Posts: 1401
Location: England. Dell Inspiron 1501. Dpup

PostPosted: Tue 29 Mar 2011, 21:56    Post subject:  

Hi L18L

I just tried your suggested command but when pasted into terminal the command doesn't work. Sad

i tried this slight variant which i think is what you probably meant - this does indeed copy to the file however it seems by using the quote marks in the command it alters the output.

echo $(awk "NR==7 { print $4 $2 }" /proc/cpuinfo)

which resulted in the whole line being printed and not the desired $4 and $2

whole line.
cpu MHz : 800.000
desired result.
800.000MHz

Confused
Back to top
View user's profile Send private message 
CatDude


Joined: 03 Jan 2007
Posts: 1470
Location: UK

PostPosted: Wed 30 Mar 2011, 05:31    Post subject:  

Hello stu90

How about this ?
Code:
echo "echo \$(awk 'NR==7 { print \$4,\$2 }' /proc/cpuinfo)" > /root/file


that results in this in the /root/file
Code:
echo $(awk 'NR==7 { print $4,$2 }' /proc/cpuinfo)


which i believe is what you wanted.

CatDude
.

_________________

Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Wed 30 Mar 2011, 05:36    Post subject: proc  

Hi stu90,

as I have no experience with awk I have done it by using grep and cut on my system:
Code:

# echo `cat /proc/cpuinfo | grep 'cpu MHz' | cut -d ':' -f 2 ` MHz
1514.903 MHz
#

Note, it is not depending on "number 7" which might be changed in future versions.
Best regards
Back to top
View user's profile Send private message 
potong

Joined: 06 Mar 2009
Posts: 88

PostPosted: Wed 30 Mar 2011, 07:08    Post subject:  

stu90:

For scripts that write scripts, I've found the here-document to be your friend.
Code:
# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 7
model name      : Pentium III (Katmai)
stepping        : 3
cpu MHz         : 598.584
cache size      : 512 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pse36 mmx fxsr sse up
bogomips        : 1197.16
clflush size    : 32
power management:

# awk 'NR==7{print $4$2}' /proc/cpuinfo
598.584MHz
# cat <<\EOF >/tmp/file                 # N.B. '\' before EOF!
> awk 'NR==7{print $4$2}' /proc/cpuinfo
> EOF
# . /tmp/file
598.584MHz
# #
# # for a bash only solution try using arrays
# #
# O=$IFS IFS=$'\n' cpuinfo=($(</proc/cpuinfo )) IFS=$O
# cpuspeed=(${cpuinfo[6]})
# echo ${cpuspeed[3]}${cpuspeed[1]}
598.584MHz
#

HTH

Potong
Back to top
View user's profile Send private message 
stu90


Joined: 25 Feb 2010
Posts: 1401
Location: England. Dell Inspiron 1501. Dpup

PostPosted: Wed 30 Mar 2011, 09:56    Post subject:  

Great stuff - thanks guys, these commands worked a treat.

I will mark this one as solved - cheers. Cool
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11092
Location: The Peoples Republic of California

PostPosted: Fri 01 Apr 2011, 12:42    Post subject:  

</proc/cpuinfo grep "cpu MHz"|awk '{print $4$2}'

outputs for me 2129.971MHz

Is that what is wanted?

The idea is to run as few commands as possible. Also, I'm going to setup a
small ramdisk for commonly used utilities and put it first in the path.


It takes a fraction of a second to have rc.local setup a ram disk

You make /var/bin as an example, then

mount -t tmpfs none /var/bin -o size=10m

For a 10mb dedicated RAM disk.

Put /var/bin as first in path statement in /etc/profile

Unzip your utilities package to /var/bin, adjust size as needed.

~

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0597s ][ Queries: 12 (0.0034s) ][ GZIP on ]