Shifting text


 
Thread Tools Search this Thread
Top Forums Programming Shifting text
# 1  
Old 05-10-2012
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?

Code:
void prValue4_vd (
  FILE*  stream,           // name of output stream
  const char*  value,      // value associated with argument action key
  const char*  desc ) {    // description

    const char* frValue4_vd;
    frValue4_vd = "    \e[1;32m%s\e[0;37m    %s\e[0m\n";
    fprintf ( stream, frValue4_vd, value, desc );

}

void prValue8_vd (
  FILE*  stream,           // name of output stream
  const char*  value,      // value associated with argument action key
  const char*  desc ) {    // description

    const char* frValue8_vd;
    frValue8_vd = "        \e[1;32m%s\e[0;37m    %s\e[0m\n";
    fprintf ( stream, frValue8_vd, value, desc );

}

---------- Post updated at 06:33 PM ---------- Previous update was at 05:38 PM ----------

Done
Code:
void prDfltValue8_vd (
  FILE*  stream,           // name of output stream
  string  value,      // value associated with argument action key
  string  desc,       // description
  int  shift ) {           // shift

    string shft(shift,' ');
    string frValue8_vd = shft + "\e[42;1m \e[0m \e[1;32m%s\e[0;37m    %s\e[0m\n";
    const char* format = frValue8_vd.c_str();
    const char* val = value.c_str();
    const char* dsc = desc.c_str();
    fprintf ( stream, format, val, dsc );

}

# 2  
Old 05-10-2012
Here is how it can be done...
Code:
const char* frValue4_vd;
int shift = 4;
frValue4_vd = "%*s\e[1;32m%s\e[0;37m    %s\e[0m\n";
fprintf ( stream, frValue4_vd, shift, " ", value, desc );

where "shift" can be passed in as a function argument...
This User Gave Thanks to shamrock For This Post:
# 3  
Old 05-10-2012
Quote:
Originally Posted by shamrock
Here is how it can be done...
Code:
const char* frValue4_vd;
int shift = 4;
frValue4_vd = "%*s\e[1;32m%s\e[0;37m    %s\e[0m\n";
fprintf ( stream, frValue4_vd, shift, " ", value, desc );

where "shift" can be passed in as a function argument...
This is better. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Shifting of data because of special characters

Hi Forum. I have a unique problem that I'm hoping someone can assist me. I'm generating a fixed width file and one of the output column (person_name at col. pos.#483 defined as string(36) sometimes contains french characters in the name and it causes the next column of data to shift to the... (10 Replies)
Discussion started by: pchang
10 Replies

3. Shell Programming and Scripting

Fields shifting in file, do to null values?

The below code runs and creates an output file with three sections. The first 2 sections are ok, but the third section doesn't seem to put a . in all the fields that are blank. I don't know if this is what causes the last two fields in the current output to shift to a newline, but I can not seem... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Print . in blank fields to prevent fields from shifting

The below code works great, kindly provided by @Don Cragun, the lines in bold print the current output. Since some of the fields printed can be blank some of the fields are shifted. I can not seem too add . to the blank fields like in the desired output. Basically, if there is nothing in the field... (10 Replies)
Discussion started by: cmccabe
10 Replies

5. Shell Programming and Scripting

Problem with blanks, shifting the row when using awk

Hello, I have files with fixed length fields. 12345 12345 12345671234567 10 1234567 12345 12345 123456 1234567 10 1234567 I want to take 1st, 3rd, 4th and 6th string. Usually 3rd and 4th string are coming as it is on the first row /1234567 and... (3 Replies)
Discussion started by: apenkov
3 Replies

6. Shell Programming and Scripting

Insert and shifting data at column

Hi all, i have data like this joe : 1 :a bob : 2 :b sue : 3 :c foo : 4 :d at column 2 i want to insert TOP to the top column and at column 3 i want to insert BOTTOM to the bottom column. and the result will... (12 Replies)
Discussion started by: psychop13
12 Replies

7. Shell Programming and Scripting

Shifting result of echo by specific amount

I am using 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 Replies)
Discussion started by: kristinu
2 Replies

8. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

9. UNIX for Dummies Questions & Answers

shifting space from one partition to other

hi My System is Sun Microsystems Inc. SunOS 5.10 Solaris Partition Info is /dev/vx/dsk/bootdg/var 27G 25G 1.2G 96% /var /dev/vx/dsk/bootdg/oravol 110G 54G 56G 49% /export/home I want to shift space 20G from /export/home to /var What should be the command ?? (2 Replies)
Discussion started by: kaushik02018
2 Replies

10. 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
Login or Register to Ask a Question