Sponsored Content
Top Forums Shell Programming and Scripting Left pad spaces using awk or sed Post 302742031 by Scrutinizer on Monday 10th of December 2012 11:40:58 AM
Old 12-10-2012
Code:
awk '{$2=sprintf("%4s",$2); $3=sprintf("%5s",$3); $5=sprintf("%3s",$5)}1' FS=\| OFS=\| file


Last edited by Scrutinizer; 12-10-2012 at 12:54 PM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pad spaces

Hello, I have to write a function to input a Label and a number, and output a line as the following format: Column 1 to 30: field label, left justified. Column 31 to 45: A number, right justified. The middle is padded with space. May I know how can I achieve this? (I don't know how to count... (3 Replies)
Discussion started by: sarahho
3 Replies

2. Shell Programming and Scripting

Left join on files using awk

nawk 'NR==FNR{a;next} {if($1 in a) print $1,"Found" else print}' OFS="," File_B File_A The above code is not working help is appreciated (6 Replies)
Discussion started by: pinnacle
6 Replies

3. Shell Programming and Scripting

Fixed Width Join & Pad Sed/Awk Help

I was wondering someone might be able to push me in the right direction, I am writing a script to modify fixed-width spool files, As you can see below the original spool file broke a single line into two for printability sake. I have had been able do the joins using sed, the thing I am... (10 Replies)
Discussion started by: Cho Nagurai
10 Replies

4. Linux

sed couldn't flush stdout no space left on device

I am running Oracle Linux enterprise server 5.0. I just installed JDE 9.0 and after I started Webserver my root directory is 100% full. Can some one help me flush stdout. I am new to linux. Sam (5 Replies)
Discussion started by: s1a2m3
5 Replies

5. Shell Programming and Scripting

How to remove spaces using awk,sed,perl?

Input: 3456 565 656 878 235 8 4 8787 3 7 35 878 Expected output: 3456 565 656 878 235 8 4 8787 3 7 35 878 How can i do this with awk,sed and perl? (10 Replies)
Discussion started by: cola
10 Replies

6. Shell Programming and Scripting

How to delete ending/trailing spaces using awk,sed,perl?

How to delete ending/trailing spaces using awk,sed,perl? Input:(each line has extra spaces at the end) 3456 565 3 7 35 878 Expected output: 3456 565 3 7 35 878 (5 Replies)
Discussion started by: cola
5 Replies

7. Shell Programming and Scripting

Unix Cut or Awk from 'Right TO Left'

Hello, I want to get the User Name details of a user from a file list. This list can be in the format: FirstName_MiddleName1_LastName_ID FirstName_LastName_ID FirstName_MiddleName1_MiddleName2_LastName_ID What i want it to return is FirstName_MiddleName1_LastName of a user. I... (6 Replies)
Discussion started by: limamichelle
6 Replies

8. Shell Programming and Scripting

left join using awk

Hi guys, I need to use awk to join 2 files file_1 A 001 B 002 C 003 file_2 A XX1 B XX2 output desired A 001 XX1 B 002 missing C 003 XX2 thank you! (2 Replies)
Discussion started by: g1org1o
2 Replies

9. Shell Programming and Scripting

left join using awk

Hi guys, I need AWK to merge the following 2 files: file1 1 a 1 1 2 b 2 2 3 c 3 3 4 d 4 4 file2 a a/a c/c a/c c/c a/a c/t c c/t c/c a/t g/g c/c c/t desired output: 1 a 1 1 a/a c/c a/c c/c a/a c/t 2 b 2 2 x x x x x x 3 c 3 3 c/t c/c a/t g/g c/c c/t 4 d 4 4 x x x x x x (2 Replies)
Discussion started by: g1org1o
2 Replies

10. Shell Programming and Scripting

awk pad 1 column with leading zero if char > 12

Hello, I got a question. I have several csv files with lots of data in it and for the first column i have EAN codes. The problem that i am facing is that some of these codes have the leading 0 removed so they are 12 or less chars while a EAN code is (always?) 13 chars. For this i used a... (9 Replies)
Discussion started by: SDohmen
9 Replies
sprintf(9F)						   Kernel Functions for Drivers 					       sprintf(9F)

NAME
sprintf, snprintf - format characters in memory SYNOPSIS
#include <sys/ddi.h> char *sprintf(char *buf, const char *fmt, ...); size_t snprintf(char *buf, size_t n, const char *fmt, ...); INTERFACE LEVEL
Solaris DDI specific (Solaris DDI). PARAMETERS
buf Pointer to a character string. fmt Pointer to a character string. DESCRIPTION
sprintf() builds a string in buf under the control of the format fmt. The format is a character string with either plain characters, which are simply copied into buf, or conversion specifications, each of which converts zero or more arguments, again copied into buf. The results are unpredictable if there are insufficient arguments for the format; excess arguments are simply ignored. It is the user's responsibility to ensure that enough storage is available for buf. The snprintf() function is identical to sprintf() with the addition of the argument n, which specifies the size of the buffer referred to by buf. The buffer is always terminated with the null byte. Conversion Specifications Each conversion specification is introduced by the % character, after which the following appear in sequence: An optional value specifying a minimum field width for numeric conversion. The converted value will be right-justified and, if it has fewer characters than the minimum, is padded with leading spaces unless the field width is an octal value, then it is padded with leading zeroes. An optional l (ll) specifying that a following d, D, o, O, x, X, or u conversion character applies to a long (long long) integer argument. An l (ll) before any other conversion character is ignored. A character indicating the type of conversion to be applied: d,D,o,O,x,X,u The integer argument is converted to signed decimal (d, D), unsigned octal (o, O), unsigned hexadecimal (x, X) or unsigned decimal (u), respectively, and copied. The letters abcdef are used for x conversion. The letters ABCDEF are used for X conversion. c The character value of argument is copied. b This conversion uses two additional arguments. The first is an integer, and is converted according to the base specified in the second argument. The second argument is a character string in the form <base>[<arg>...]. The base supplies the conversion base for the first argument as a binary value; 10 gives octal, 20 gives hexadecimal. Each subsequent <arg> is a sequence of characters, the first of which is the bit number to be tested, and subsequent characters, up to the next bit number or terminating null, supply the name of the bit. A bit number is a binary-valued character in the range 1-32. For each bit set in the first argument, and named in the second argument, the bit names are copied, separated by commas, and bracketed by < and >. Thus, the following function call would generate reg=3<BitTwo,BitOne> in buf. sprintf(buf, "reg=%b ", 3, "102BitTwo1BitOne") p The argument is taken to be a pointer; the value of the pointer is displayed in unsigned hexadecimal. The display format is equivalent to %lx. To avoid lint warnings, cast pointers to type void * when using the %p format specifier. s The argument is taken to be a string (character pointer), and characters from the string are copied until a null character is encoun- tered. If the character pointer is NULL, the string <null string> is used in its place. % Copy a %; no argument is converted. RETURN VALUES
sprintf() returns its first argument, buf. snprintf() returns the number of characters formatted, that is, the number of characters that would have been written to the buffer if it were large enough. If the value of n is less than or equal to 0 on a call to snprintf(), the function simply returns the number of charac- ters formatted. CONTEXT
sprintf() and snprintf() can be called from user or interrupt context. SEE ALSO
Writing Device Drivers SunOS 5.10 11 Feb 2003 sprintf(9F)
All times are GMT -4. The time now is 05:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy