Shifting result of echo by specific amount


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shifting result of echo by specific amount
# 1  
Old 02-20-2012
Shifting result of echo by specific amount

I am using

Code:
echo "HELLO"

I want to specify a number shiftWt so that I move hello forward by shiftWt charcaters.

Is there a way to do this?
# 2  
Old 02-20-2012
Code:
# prepend
printf  "%20s\n" "HELLO"

# 3  
Old 02-20-2012
I have coded it like this. Suppose I want to have 3 blank characters before the string. If the string is longer than 20 characters, I would not have the 3 characters in the beginning.

Code:
set blk = ""                           # Create a blank string of size shiftWt.
@ x = 1
while ($x <= $shiftWt)
  set blk = " $blk"
  @ x += 1
end

set len = ${%strLst4}
if ($len > 0) then
  if ($i > 1) echo ""
  foreach str ($strLst4)
    echo "${blk}${str}"                # Add blank string to beginning.
  end
  @ i++
endif


Last edited by kristinu; 02-20-2012 at 06:16 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To get or print specific value in result

i am executing below code to achive my result, but for second row the value is not coming it should come URL like other two . url start with http:// and end with .xhtml cat FILE | grep 'Test failed' | awk -F',' '{print $3,$8,$12}' INPUT 1517679173303,84,SKILLED LANGUAGE - ENTER... (11 Replies)
Discussion started by: mirwasim
11 Replies

2. Shell Programming and Scripting

Run a command for specific amount of time with an auto key press

Hi, I have been trying to do a small fun project for myself. I want to run a command for 45 seconds. And to get the final output of this command, the script requires I push the "q" key on my keyboard and then the final output file becomes available. I tried the following script. But it... (12 Replies)
Discussion started by: jacobs.smith
12 Replies

3. Shell Programming and Scripting

Counting specific column and add result in output

Hi all, I have a quick question: I have a 4 column tab-separated file. I want to count the number of times each unique value in column 2 appears and add that number in a 5th column. I have the following input file: waterline-n below-sheath-v 14.8097 A dock-n below-sheath-v ... (4 Replies)
Discussion started by: owwow14
4 Replies

4. UNIX Desktop Questions & Answers

grep a specific amount of occurrence

hey , i m trying to figure out how to do the following : i got a text file the looks like so: 1031 1031 1031 1031 1031 1031 1031 1031 16500 16500 16500 16500 1031 1031 (4 Replies)
Discussion started by: boaz733
4 Replies

5. Programming

Shifting text

I have the following functions which shifts the text by 4 and 8 characters. How can I pass an integer for the shift so that the text is shifted accordingly? void prValue4_vd ( FILE* stream, // name of output stream const char* value, // value associated with argument... (2 Replies)
Discussion started by: kristinu
2 Replies

6. Homework & Coursework Questions

Using ls or echo to display a specific output

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: What single command line would you enter to get the following output? 8140 drwxr-xr-x 9 root bin 18 Jan 20... (6 Replies)
Discussion started by: dasboot
6 Replies

7. Shell Programming and Scripting

Generate specific amount of same characters

Hi, Is there a command to print one character x amont of times? I need for example 10 comma's (,,,,,,,,,,). Instead of creating a loop, I was wondering if there is a way to do this with sed or awk? Thanks! (3 Replies)
Discussion started by: Subbeh
3 Replies

8. Shell Programming and Scripting

How to format sql result as amount - ksh

I am currently returning an sql result with a number value that I want to format as an amount. The sql runs smoothly on its own, but when run inside my ksh script an error is encountered: ERROR at line 3: ORA-01481: invalid number format model My sql is -- select distinct ... (6 Replies)
Discussion started by: avillanueva
6 Replies

9. Shell Programming and Scripting

Shifting of lines in a file

Hi all, I am using the below command to shift the lines in a file which was advised by Anchal in this forum: awk -v total_records=$(cat redirects.virgin-atlantic.com.conf | wc -l) '{ if(NR>(total_records - 2)) printf "\t%s\n", $0; else print $0 }' align but I am getting the below error:... (7 Replies)
Discussion started by: Shazin
7 Replies

10. UNIX for Dummies Questions & Answers

echo command result

hello how can i print to screen the result of this command ? echo "pwd | sed 's/.*foo//'" when i type it im geting it printed as string "pwd | sed 's/.*DevEnv//'" and not the result of the operetion. tnx (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question