String format in KSH script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String format in KSH script
# 1  
Old 04-02-2009
Question String format in KSH script

Hello,

I am attempting to format the output of my unix ksh script. Currently looks like ...
FTP TO HR : Down
FTP FROM HR 4011a : Up
FTP FROM HR 4019a : Down
FTP FROM HR : Down

Would like the status to be aligned as follows:
FTP TO HR : Down
FTP FROM HR 4011a : Up
FTP FROM HR 4019a : Down
FTP FROM HR : Down

Current code is below, am stripping out the non-english part of the result:

print "\t${item} : \t\t${result}" | sed 's/ew//1' | sed 's/_SMFtoRAW//1' | sed 's/_RAWtoSMF//1' | sed 's/_/ /g'

Any sugestions would be greatly appreciated!!
Thank-you.
# 2  
Old 04-02-2009
Quote:
Originally Posted by dvella
Hello,

I am attempting to format the output of my unix ksh script. Currently looks like ...
FTP TO HR : Down
FTP FROM HR 4011a : Up
FTP FROM HR 4019a : Down
FTP FROM HR : Down

Would like the status to be aligned as follows:
FTP TO HR : Down
FTP FROM HR 4011a : Up
FTP FROM HR 4019a : Down
FTP FROM HR : Down

Current code is below, am stripping out the non-english part of the result:

print "\t${item} : \t\t${result}" | sed 's/ew//1' | sed 's/_SMFtoRAW//1' | sed 's/_RAWtoSMF//1' | sed 's/_/ /g'

Any sugestions would be greatly appreciated!!
Thank-you.

Try this

printf "\%-15${item} : \%20s${result}" | sed 's/ew//1' | sed 's/_SMFtoRAW//1' | sed 's/_RAWtoSMF//1' | sed 's/_/ /g'
# 3  
Old 04-02-2009
Thank-you for that suggestion. The first column all line up but still experiencing the same problem with the 2 column due to the different lengths of data stored in 1st column. Output below ...

FTP TO HR: Down
FTP FROM HR 4011a : Up
FTP FROM HR 4019a : Down
FTP FROM HR : Down
# 4  
Old 04-02-2009
Ok, have just noticed text isn't appearing in post as expected ... first column is indentent as required. 2nd column also indented but by the same amount from the end of the first column, rather then all starting from the same point (ie: need it to be from character position 55 for example).
# 5  
Old 04-06-2009
dvella,

If your script outputs this:
FTP TO HR : Down
FTP FROM HR 4011a : Up
FTP FROM HR 4019a : Down
FTP FROM HR : Down

try this:
script | awk -F\: '{printf("%-55s %s\n", $1, $2)}'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to filter string between specific string in ksh

My argument has data as below. 10.9.9.85 -rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr5.scr 127869538 -rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr56scr 127869538 ....... (note all these between lines will start with hyphen '-' ) -rwxr-xr-x user1 2019-10-15 17:40... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Shell Script (ksh) - SQLPlus query filter using a string variable

Using ksh, I am using SQLPlus to execute a query with a filter using a string variable. REPO_DB=DEV1 FOLDER_NM='U_nmalencia' FOLDER_CHECK=$(sqlplus -s /nolog <<EOF CONNECT user/pswd_select@${REPO_DB} set echo off heading off feedback off select subj_name from subject where... (5 Replies)
Discussion started by: nkm0brm
5 Replies

3. Shell Programming and Scripting

String manipulation using ksh script

Hi, I need to convert string "(joe.smith" into "joe_smith" i.e. I need to remove the leading opening brace '(' and replace the dot '.' with an under score '_' can anyone suggest a one liner ksh script or unix command for this please (3 Replies)
Discussion started by: sdj
3 Replies

4. Shell Programming and Scripting

How to format String in ksh

Hi, I have 3 columns to display to target file and the display of the columns with specified position in target file. I have tried with printf command The Columns position like: Column1= 0 to 30 Column2=30 to 60 Column3=60 to 90 The source data: EMPNO,ENAME,SAL 1,11,100 2,22,200... (4 Replies)
Discussion started by: koti_rama
4 Replies

5. Shell Programming and Scripting

KSH - need to write a script to abbreviate a string

Dear Members, I have to write a UNIX script (KSH) to create a 6 letter abbreviation from a given string. The string will have alphabets and underscores only. e.g. abc_pst_xyz is our string and I have to create an abbreviation which will look like 'abpsxy' or 'abcpyz' etc. Now comes the... (8 Replies)
Discussion started by: Yoodit
8 Replies

6. Shell Programming and Scripting

Read format problem in ksh script

I have ksh script reading file like while read -r line do echo $line sleep 1 #process_file $line done<$file_nm I want to write this line to another file after some manuplation.Put $line giving me line after changing line format(space removed).Please help me how can i read line by... (3 Replies)
Discussion started by: Mandeep
3 Replies

7. Shell Programming and Scripting

format decimal in ksh

hi all, in ksh, how do i format a decimal number (e.g 3381.19) to integer (e.g 3381). This number is average time response for server in millisec and i wanted to display it in a more readable format i.e in seconds without any decimals. thanks in advance. (2 Replies)
Discussion started by: cesarNZ
2 Replies

8. AIX

Problem in ksh script ( String comparison )

hi , i am trying to compre two strings if ] or if ] when the length of var1 is small (around 300-400 char ) it works fine but when it is large (around 900-1000 chars) it fails is there any limitations for this type of comparison ??? (1 Reply)
Discussion started by: amarnath
1 Replies

9. Shell Programming and Scripting

Problem in ksh script ( String comparison )

hi , i am trying to compre two strings if ] or if ] when the length of var1 is small (around 300-400 char ) it works fine but when it is large (around 900-1000 chars) it fails is there any limitations for this type of comparison ??? (3 Replies)
Discussion started by: amarnath
3 Replies

10. Shell Programming and Scripting

How to format number/string in ksh

Hi, How to format a number in ksh. For example x=RANDOM $$ I want x to be of 20 digits long, so if x = 12345 I want it to be left paded with 15 zeros. Thanks. (2 Replies)
Discussion started by: GNMIKE
2 Replies
Login or Register to Ask a Question