LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2006, 08:51 AM   #1
chloraldo
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Rep: Reputation: 0
string with content of variables


Hello

I'm trying to write the last line in a file like this (colors are just for help in here):
8518082006154522000100000000
Code:
tempfile=tempf.txt
artikel=$(grep -c ^50 $tempfile)
echo 85$(date +%d%m%Y%H%M%S)$artikel000000>>$tempfile
$artikel has a value but doesn't add it to the line. What's wrong?
$artikel should also always be a 6-digit number. How can I do that?
The 000000 at the end doesn't appear...

Thanks for your help!
 
Old 08-18-2006, 08:58 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i normally wrap a sub command for that variable, e.g. echo $(date...)$(echo $variable)00000
 
Old 08-18-2006, 09:05 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
or simply:
Code:
echo 85$(date +%d%m%Y%H%M%S)${artikel}000000>>$tempfile
otherwise, the shell will look for a variable named artikel000000.
 
Old 08-18-2006, 09:09 AM   #4
chloraldo
LQ Newbie
 
Registered: Aug 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jlliagre
or simply:
Code:
echo 85$(date +%d%m%Y%H%M%S)${artikel}000000>>$tempfile
otherwise, the shell will look for a variable named artikel000000.
Thanks that works....

Now I'm trying to get e.g. the number 6 to look like 000006 or 103 to look like 00103 etc. Any ideas?
 
Old 08-18-2006, 09:34 AM   #5
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
Quote:
Now I'm trying to get e.g. the number 6 to look like 000006 or 103 to look like 00103 etc. Any ideas?
Code:
printf '%06d' 6
(Note: if you try this on the command line, add a \n to the end of the string, or your prompt will clobber the output.)
 
  


Reply



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
Threads synchronisation problem (mutex variables and contitional variables) zahadumy Programming 6 12-07-2005 12:30 PM
how to divide two string variables user_linux Programming 3 06-20-2005 04:54 PM
String variables in DDD Qt debugger impeteperry Linux - Software 0 06-12-2005 07:57 AM
Apache serving content after the content is removed? jrbush82 Linux - Software 6 05-05-2004 04:39 AM
Replacing String with File Content in Sed meshcurrent Linux - General 2 06-01-2003 12:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 PM.

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