Leading blanks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Leading blanks
# 1  
Old 03-01-2013
Leading blanks

Hi

Ich have a list as follows

Code:
73
5
100
45
81
4

and I would like to have an output (on screen) like that

Code:
  73
   5
100
 45
 81
  4

googled and tried a lot (printf and sed) but got no satisfactory result.

Can anyone help?

Thanks
Lazy

---------- Post updated at 06:35 PM ---------- Previous update was at 06:34 PM ----------

Hi

Of course, the leading blanks in the second list disappeared ...

Lazy

Last edited by Scrutinizer; 03-01-2013 at 03:20 PM..
# 2  
Old 03-01-2013
Please edit your text again and wrap it in CODE tags.
(The tags are at the top of the WIKI editor.)
# 3  
Old 03-01-2013
What about
Code:
$ while read tmp; do printf "%10s\n" $tmp; done < file
        73
         5
       100
        45
        81
         4

# 4  
Old 03-01-2013
Quote:
Originally Posted by lazybaer
Hi

Ich have a list as follows

73
5
100
45
81
4

and I would like to have an output (on screen) like that

Code:
  73
   5
100
 45
 81
  4

googled and tried a lot (printf and sed) but got no satisfactory result.

Can anyone help?

Thanks
Lazy

---------- Post updated at 06:35 PM ---------- Previous update was at 06:34 PM ----------

Hi

Of course, the leading blanks in the second list disappeared ...

Lazy
I added code tags to show the output I assume you want. If your list of numbers is in a file named list, the following seems to do what you want:
Code:
#!/bin/ksh
i=1
while read n
do      if [ $i -lt 3 ]
        then    printf "%4d\n" "$n"
        else    printf "%3d\n" "$n"
        fi
        i=$((i + 1))
done < list

# 5  
Old 03-01-2013
Was ich habe, ist ein ermittelter Wert

Code:
56
6
100
45

und was ich möchte, sollte so aussehen

Code:
 56
  6
100
 45

zB auf dem Bildschirm

Lazy

Last edited by Scrutinizer; 03-01-2013 at 03:28 PM.. Reason: Too many code tags
# 6  
Old 03-01-2013
English please!
And you wrapped in ICODE - CODE looks better.

---------- Post updated at 01:07 PM ---------- Previous update was at 01:01 PM ----------

Code:
printf "%3s\n" `cat file`
awk '{printf "%3s\n",$0}' file

# 7  
Old 03-01-2013
I have now the solution, thanks RudiC

Looks like that

Code:
printf "%3s" $4; echo " % xxx yyyyyyy zzzzz"

Regards
Lazy

Last edited by Scrutinizer; 03-01-2013 at 03:24 PM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Screen blanks when exiting vi and more

I have just installed AIX 7.1 on a new system, and find that it displays the same annoying behaviour the you find in Linux: In an xterm, when you quit vim or less, the file listed in the terminal window is blanked out and replaced with whatever was there before. In vim there is a couple of... (12 Replies)
Discussion started by: jandersen
12 Replies

2. Shell Programming and Scripting

Removing blanks, spaces

I have pipe separated file with lots of blank spaces. After using sed -e 's/ *| */|/g' this command ,its giving me output as TT0000013101640| HCAMBLAMCNB010|Jul 3 2012 11:14AM| HARYANA| Bangali Mohalla | TCL-UBR|9368040005|9355264655|9218509220|NULL ... (5 Replies)
Discussion started by: sususa
5 Replies

3. Shell Programming and Scripting

Clearing leading and trailing blanks from a string in C Shell

Does anyone know of a way with C Shell that will work on both Linux and Sun to clear all leading and trailing blanks from a previously specified string? I am using the following code to replace blanks with underscores: set Company = `echo $Company | sed 's/ /_/g but I don't want any... (1 Reply)
Discussion started by: phudgens
1 Replies

4. Shell Programming and Scripting

Remove multiple blanks

Hi, I have data as below And I want output as Thanks (5 Replies)
Discussion started by: Anjan1
5 Replies

5. Shell Programming and Scripting

moving a file having blanks in its name

Hi , i need to write a simple to script in KSh to move some files , but these files have spaces in there name, resulting in error in transfering eg i have following files 30222_Deal Ticket_20071227203.csv 30222_Deal Ticket_20071227204.csv 30222_Deal Ticket_20071227205.csv and i want to... (7 Replies)
Discussion started by: Anand28
7 Replies

6. Programming

Blanks vs: Nulls

I'm relatively new to Pro*C programming. In the following example: char name; EXEC SQL SELECT 'John Doe' INTO :name FROM DUAL; "John Doe" is in positions 0-7, blanks in 8-19, and a null in 20. I would really prefer the null to be in position 8 and I don't care what's after that. I wrote a... (1 Reply)
Discussion started by: ebock
1 Replies

7. UNIX for Advanced & Expert Users

numbering blanks

hello i'm trying to figure out how to number a blank line. For instance this : sed '/./=' file | sed '/./N; s/\n/ /' gives me 1 aaaa 2 bbbbbb 4 cccccc 5 ffkkkfff 6 ffsdfdfs I would like something like this: 1 aaaaa 2 3 bbbbbb 4 5 cccccc And so... (6 Replies)
Discussion started by: wisher115
6 Replies

8. Shell Programming and Scripting

blanks in file name

I have a file with a list of filenames. I want to work loopwise through the file and operate on each of the listed files. Normally I'd do something like: for file in `cat $mydir/file-list` do echo $file >> $mydir/my.log cp $mydir/$file $newdir done the problem is that my... (1 Reply)
Discussion started by: LisaS
1 Replies

9. UNIX for Advanced & Expert Users

FTP Between UNIX & Windows drops leading blanks

I am using ftp on Solaris to transfer files to Windows 2000 that have leading blanks in the name (ex. " 12345A4444.BIN"). When they get to Windows the leading blanks are stripped off. Has anyone encountered this and is there a fix? If I use Hummingbird it is ok but that is not an option for... (6 Replies)
Discussion started by: worf52
6 Replies

10. Shell Programming and Scripting

blanks in an awk comand

Hi, Im trying to write something that will report if a filesytem is over 80% but the problem is the output reports on a dir that is a 9%. any ideas? this is what I have ************************************************* if then param=90 else param=$1 fi df -kl | grep... (1 Reply)
Discussion started by: collie
1 Replies
Login or Register to Ask a Question