The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Difference between using "echo" builtin and /bin/echo ulidtko Shell Programming and Scripting 2 07-15-2009 12:12 PM
Using echo in AWK jermaine4ever Shell Programming and Scripting 10 03-12-2009 01:24 PM
echo tontal Shell Programming and Scripting 2 11-15-2006 12:20 PM
FTP--How to use echo?? rahul26 UNIX for Advanced & Expert Users 1 06-14-2006 10:47 AM
How to set echo on siegfried Shell Programming and Scripting 1 11-18-2005 01:56 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2009
Samtel Samtel is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 7
Using Echo

Hi All,

Need help in resoving the issue . Can anyone let me know how to get fix length using unix shellscript.

For Ex: echo "NUMBER OF RECORDS "${NO_OF_ROWS}"\nFILE CREATION DATE&TIME "${PROD_DT}"

output should be :

NUMBER OF RECORDS 2546
CREATIN DATE&TIME 2009-12-01

Each record created in Unix should be of 80 byte length

Kindly help me out on the same
  #2 (permalink)  
Old 08-24-2009
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Take the spurious quotes out of the middle of the echo, and put the second line of output in a second echo. That should produce the output you need.

You'll need to clarify what you mean by "Each record created in Unix should be of 80 byte length" as nothing in your question implies you are creating anything at all...
  #3 (permalink)  
Old 08-24-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,183
The script will be easier to read as two commands:

Code:
echo "NUMBER OF RECORDS ${NO_OF_ROWS}"
echo "FILE CREATION DATE&TIME ${PROD_DT}"
I too don't understand "Each record created in Unix should be of 80 byte length".
  #4 (permalink)  
Old 08-25-2009
KenJackson KenJackson is offline
Registered User
  
 

Join Date: May 2008
Location: Maryland, USA
Posts: 107
Quote:
Originally Posted by Samtel View Post
Can anyone let me know how to get fix length using unix shellscript.
...
Each record created in Unix should be of 80 byte length
Are you trying to create text files in which each line has exactly 80 characters?

The echo command seems to automatically strip off leading and trailing whitespace, which thwarts you. But this should work:
Code:
IFS= echo "Whatever ...                            " > outfile
The IFS variable is very special. The echo command consults it before interpreting whitespace. I've made it blank in the above example.


If you are counting lines in a file, use the wc command.
Code:
wc -l file
  #5 (permalink)  
Old 08-25-2009
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172
Or if you still want to use echo, use -e to enable interpretation of backslash escape sequences.
Code:
$ echo -e "first line\nsecond line"
first line
second line
  #6 (permalink)  
Old 08-25-2009
Samtel Samtel is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 7
Using Echo

Hey,

This is what i am looking for ... i have a shellscript whcih creates a report. Report has got 5 rows and each row should start from byte 1 and end at byte 80 . This should follow for the remainign 5 rows ..... hope this explains .....
  #7 (permalink)  
Old 08-25-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,183
Did you mean like this?

Code:
printf "%-73s%-7s" "hello" "goodbye"
hello                                                                    goodbye
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0