Inserting spaces after a value in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting spaces after a value in UNIX
# 1  
Old 12-02-2009
Inserting spaces after a value in UNIX

Hi All,

I need to prepare a shell script in UNIX to insert 400 spaces after a variable in a file "file.txt".

Eg. if n=T12345
echo $n >> file.txt

cat file.txt should give:
T12345<400 spaces>

Please advice.

Thanks in advance !!
# 2  
Old 12-02-2009
# 3  
Old 12-02-2009
Thanks for the reply Scottn !!

I tried the same:
printf "$n%400s" >> file.txt

Although it is inserting the required number of spaces in file.txt, it also gives the message:
printf: 400s: No such file or directory
printf: No such file or directory

Can you please advice.
# 4  
Old 12-02-2009
You must be doing something else (or using a funny shell! - which shell are you using?)

Show the code you are running, as that piece of code is fine:

Code:
$ echo $n
123
$ printf "$n%400s" >> file.txt
$ wc -c file.txt
403 file.txt

# 5  
Old 12-02-2009
Hi Scottn,

I am using ksh:

$ echo $SHELL
/bin/ksh
# 6  
Old 12-02-2009
That's not a funny shell!

I was hoping you'd post some code so that I could see exactly what you were doing that would give this error...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get a numeric value from Oracle to UNIX variable without spaces?

Hi, I am using the below code to get a numeric value from oracle to unix variable: BD_RC_CNT=`sqlplus -s ${WMD_DM_CONNECT} <<EOF set heading off set pagesize 0 Select count(*) from wmd_bad_data where proc_id = ${PROC_ID} and file_id = ${FILE_ID} and file_dt =... (7 Replies)
Discussion started by: Arun Mishra
7 Replies

2. Shell Programming and Scripting

Inserting date in unix shell with awk

Hi Friends, I have to insert date in a shell script in awk command., Shell script which i have written split on file into multiple and rename them based on some values. I want to add timestamp in the file name which is formed in after splitting the files. Dont know where am doing the mistake... (6 Replies)
Discussion started by: manish8484
6 Replies

3. Shell Programming and Scripting

trim spaces in unix for variable

HI Guys I have written a script using awk to split a file based on some identifier and renaming the file based on two values from specific length. ts a fixed width file. When I am trying to fetch the values a = substr($0,11,10) b = substr($0,21,5); i am getting spaces in a and b values .... (6 Replies)
Discussion started by: manish8484
6 Replies

4. Shell Programming and Scripting

Trimming Spaces in Unix

Hi All, I am using following script to name the file base of some values #!/bin/sh sourcefile=$1 awk ' BEGIN{ n = 1; name = "FILEFILE12" n ".txt"; } { if (substr($0,1,10) == "FILEFILE12") { close (name) n++ a = substr($0,11,10); b = substr($0,21,5); name = b "_Src_" a ".txt" }... (6 Replies)
Discussion started by: manish8484
6 Replies

5. Shell Programming and Scripting

sql loader for inserting the data from multiple fields from unix

Hi , I have my log file something like this (07/29/2009 00:02:24.467) 367518 (07/29/2009 00:02:26.214) 949384011 (07/29/2009 00:02:26.236) 367524 (07/29/2009 00:02:28.207) 949395117 (07/29/2009 00:02:28.240) 337710 (07/29/2009 00:02:30.621) 949400864 I am trying to insert the data... (3 Replies)
Discussion started by: rdhanek
3 Replies

6. Shell Programming and Scripting

Inserting spaces in a record

Hi all. I am using /bin/sh on an HPUX system. I have a file, with records as such: 60701006000000030380000000000000030380000400000000000 61001006000000008220000000000000008220000100000000000 61201006000000030150000000000000030150001000000000000 I know the character counts which... (5 Replies)
Discussion started by: lyoncc
5 Replies

7. Shell Programming and Scripting

Unix filenames and spaces

I have files on my unix boxes that users have created with spaces. Example: /tmp/project plan ls -l "/tmp/project plan" works fine. $/tmp>ls -l "/tmp/project plan" -rw-r--r-- 1 root other 0 Jan 31 12:32 /tmp/project plan I created a file called test and put just the... (2 Replies)
Discussion started by: x96riley3
2 Replies

8. Shell Programming and Scripting

delete spaces in the variable in unix script?

Hi All, I need your help.I want to know how to delete the spaces in a variable in unix scripting.Please give solution to this probelm... thanks ! :confused: (14 Replies)
Discussion started by: MARY76
14 Replies

9. UNIX for Dummies Questions & Answers

To remove the extra spaces in unix

Hi... I am quite new to Unix and would like an issue to be resolved. I have a file in the format below; 4,Reclaim,ECXTEST02,abc123,Harry Potter,5432 6730 0327 5469,0603,,MC,,1200,EUR,sho-001,,1,,,abc123,1223 I would like my output to be as follows; 4,Reclaim,ECXTEST02,abc123,Harry... (4 Replies)
Discussion started by: Sho
4 Replies

10. Shell Programming and Scripting

handling spaces in unix

I am testing a ksh script for email. In the script I receive several parameters. One of them is a subject. The subject may contain spaces. Ex. Test this. When I am running the script on telnet to test, how should the syntax at the command line be written. I have this: ksh ResendE.sh '001111'... (2 Replies)
Discussion started by: supercbw
2 Replies
Login or Register to Ask a Question