|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Add characters at specific position in file
Hello I want to add some value at the specific position. My file has data like Hello Welcome to UNIX Forums Need Assistance I want to add some value at the end but at same character position for all lines. I want my output file to have data like : Here '_' represents blanks. Hello_____________________Everyone Welcome to UNIX Forums____Everyone Need Assistance___________Everyone The data to be appended at last is same. I am using this command : Code:
sed "s/$/'Everyone'/" myfile However it is appending where my line is ending.i.e. Hello'Everyone' Welcome to UNIX Forums'Everyone' Need Assistance'Everyone' Any suggestions.[COLOR="#738fbf"] |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Something like this: Code:
awk '{len=30-length;printf("%s%*s\n",$0,len,"Everyone")}' file |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
You can use "printf" to format the input to the specified length. See the printf manual for complete syntax.
|
|
#4
|
|||
|
|||
|
Thanks for valuable reply... I am using this command . Code:
awk '{len=4000-length;printf("%s%*s\n",$0,len,$var1$var2)}' $FILEHowever I am getting an error : Code:
awk: Field is not correct .The input line number is 1.The file is /.../abc.txt . The Source line number is 1. Please help me in correcting this error. ---------- Post updated at 04:56 PM ---------- Previous update was at 04:21 PM ---------- THANK YOU EVERY ONE !!! UNIX FORUMS ROCKK !!! ![]() I GOT THE SOLUTIONS. ![]() I LEARNED THAT I NEED TO PUT MY VARIABLES IN "'" QUOTES INSIDE AWK... ![]() CHEERS !!!
|
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Insert character in a specific position of a file | gpaulose | Shell Programming and Scripting | 1 | 10-07-2009 12:27 PM |
| Print lines with specific character at nth position in a file | manaswinig | Shell Programming and Scripting | 1 | 06-04-2009 09:01 AM |
| Print lines with specific character at nth position in a file | manaswinig | Shell Programming and Scripting | 2 | 06-04-2009 09:00 AM |
| Deleting Characters at specific position in a line if the line is certain length | Cailet | Shell Programming and Scripting | 10 | 12-17-2008 01:41 PM |
| read space filled file and replace text at specific position | COD | Shell Programming and Scripting | 6 | 04-21-2008 05:40 AM |
|
|