![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| appending spaces to first line based on second record. | ammu | Shell Programming and Scripting | 2 | 11-16-2007 03:35 AM |
| adding spaces to a line | mgirinath | Shell Programming and Scripting | 4 | 03-23-2007 12:38 PM |
| To Trim spaces at the end of line | sbasetty | Shell Programming and Scripting | 1 | 01-31-2007 10:01 PM |
| Append strings with filler spaces | handak9 | UNIX for Dummies Questions & Answers | 1 | 08-11-2005 10:51 AM |
| Strip leading and trailing spaces only in a shell variable with embedded spaces | jerardfjay | Shell Programming and Scripting | 6 | 03-07-2005 02:24 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
how to append spaces(say 10 spaces) at the end of each line based on the length of th
Hi,
I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed to append spaces to the new file.However the data in each line can have multiple spaces in between and I am losing those extra spaces while copying the line into another file. For eg: while read line a=${#line} do if ((a==100)) echo $line >> tempfile fi done<sourcefile The problem with the same code is its suppressing multiple spaces into one space if the line has multiple spaces. Please help |
|
||||
|
TO append Blank Spaces
Hi ,
i need awk command for which it appends 100 blank spaces for Header (starts wirh H..) and Trailer (starts with T..) in a file. HODACC(need to add 100 blank spaces here) D0000... D0000..... .. .. T000013(need to add 100 blank spaces here) thanks... |
|
||||
|
thanks for reply.....
I am new to unix.... I require to append 100 spaces(fillers) to header(first line) and 100 space to trailer(last line). the data in the middle not to be changed. i do not want variable length record file turned into a fixed width record file. i just need to append 100 fillers in the first line and 100 fillers in last line sample file: HODA(need to add 100 fillers(spaces) here) D0000000000000000000000000000000000 D0000000000000000000000000000000000 T000012(need to add 100 fillers(spaces) here) |
|
||||
|
Try something like this:
Code:
awk -v n=`wc -l < file` '
BEGIN{s=sprintf("%-100s", "")}
NR==1{$0=$0 s)}
NR==n{$0=$0 s)}
1' file
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|