Sponsored Content
Top Forums Shell Programming and Scripting Awk command to replace specific position characters. Post 302594587 by pinnacle on Tuesday 31st of January 2012 06:34:22 PM
Old 01-31-2012
Awk command to replace specific position characters.

Hi,
I have a fixed width file.
The way this file works is say for example there are 30 columns in it each with different sizes say 10,5,2, etc...
If data in a field is less than the field size the rest of it is loaded with spaces.
I would like an awk command to that would replace
Quote:
position 96-98 with "ABC"
position 99-113 with "DEF" rest of it with spaces
position 190-198 with "XYZ" rest of it with spaces
I have tried following but doesnt work
Code:
 
awk '{printf "%-"ABC"s\n",$0}' File> File1

Please let me know with the correct command.

---------- Post updated at 07:34 PM ---------- Previous update was at 06:35 PM ----------

I now tried this:

Code:
 
awk -F "" '{for (i=1;i<=NF;i++) if (i==96||i==97||i==98) $i="ABC"}1' OFS="" urfile

Need help with little more tweaking.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read space filled file and replace text at specific position

Hi I have a spaced filled file having records like below: What I want is to read line having RT3 at position 17-19 then go to position 2651 check the 18 characters (might be space filled till 18 characters). This position should have a... (6 Replies)
Discussion started by: COD
6 Replies

2. Shell Programming and Scripting

Using sed to replace specific character and specific position

I am trying to use sed to replace specific characters at a specific position in the file with a different value... can this be done? Example: File: A0199999123 A0199999124 A0199999125 Need to replace 99999 in positions 3-7 with 88888. Any help is appreciated. (5 Replies)
Discussion started by: programmer22
5 Replies

3. Shell Programming and Scripting

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.... (3 Replies)
Discussion started by: dashing201
3 Replies

4. Shell Programming and Scripting

Sed position specific replace

I'm drawing a blank on how to use sed to replace selectively based on position in the string (vs nth occurence): hello.|there.|how.|are.|you.| I want the period removed in the 3rd item (as defined by the pipe delimiter) if a period is present. So the result in this case would be: ... (2 Replies)
Discussion started by: tiggyboo
2 Replies

5. Shell Programming and Scripting

Using sed to replace a string in a specific position

I asked this before, but my problem got more complicated. Heres what I am trying to do: I'm trying to replace a string at a certain location with another string. Heres the file I'm trying to change: \E I want to replace the escape code at the 3rd line, 2nd column with this escape code... (3 Replies)
Discussion started by: tinman47
3 Replies

6. Shell Programming and Scripting

position specific replace in file

How to replace the position specific values in the file.. i searched a lot the forums but i couldn't able to do... i have file like below 576666666666666666666666666 7878 897987 121 0asdas Y12 5900fbb 777 09JJJ 78798347892374 234234234364 234232898 89HJHIHIGIUG989902743748327khjkhkjlh... (6 Replies)
Discussion started by: greenworld123
6 Replies

7. Shell Programming and Scripting

Printing characters at specific position in line

Hi, I am trying to get an output like : +----------------------------------+ ----------- + + some variable substitution + some text + Is there a way I can specify in printf (in ksh) the particular position I want to print a character, and also repeat a character from... (1 Reply)
Discussion started by: neil.k
1 Replies

8. Shell Programming and Scripting

Find and replace with 0 for characters in a specific position

Need command for position based replace: I need a command to replace with 0 for characters in the positions 11 to 20 to all the lines starts with 6 in a file. For example the file ABC.txt has: abcdefghijklmnopqrstuvwxyz 6abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz... (4 Replies)
Discussion started by: thangabalu
4 Replies

9. Post Here to Contact Site Administrators and Moderators

Search for a pattern and replace a space at specific position with a Character in File

In file, we have millions of records each of 1000 in length. And at specific position say 800 there is a space, we need to replace it with Character X if the ID in that row starts with 123. So far i have used the below which is replacing space at that position to X but its not checking for... (3 Replies)
Discussion started by: Jagmeet Singh
3 Replies

10. Shell Programming and Scripting

sed command on AIX, replace specific characters

Hi, Im using sed on an AIX machine. I am trying to change the 137-139 characters if they are a ' 36'/'000' to a '036'. The positions that need to be changed are fixed. the source data that I have is$cat v.txt 4000422985400050462239065593606500000007422985707771046154054910075641MC0318AMWAY... (9 Replies)
Discussion started by: dsid
9 Replies
PCLOCK(1)						      General Commands Manual							 PCLOCK(1)

NAME
pclock - pixmap clock SYNOPSIS
pclock [options] DESCRIPTION
This manual page documents briefly the pclock command. This manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual page. pclock is a program that places a small analog clock program on the desktop of X. It was designed to run under the WindowMaker window man- ager. It uses any 64x64 pixmap as a background. OPTIONS
The programs follow the usual GNU command line syntax, with long options starting with two dashes (`-') and short optoins starting with one dash. A summary of options is included below. -B PIXMAP, --background=PIXMAP Use the given pixmap as the clock background (size must be 64x64). -H COLOR, --hands-color=COLOR Draw the hands (hour, minute and second) in the specified color. -S COLOR, --second-hand-color Draw the second hand in the specified color -h, --help Show summary of options. --hour-hand-length=INT Draw the hour hand with the specified length of INT. --minute-hand-length=INT Draw the minute hand with the specified length of INT. --second-hand-length=INT Draw the second hand with the specified length of INT. --second-hand-width=INT Draw the minute hand with the specified width of INT. -s, --second-hand Don't display the second hand. -v, --version Show version of program. -w, --withdrawn Don't start up in a withdrawn (iconic) state. AUTHOR
This manual page was written by Darren Benham <gecko@debian.org>, for the Debian GNU/Linux system (but may be used by others). The soft- ware is copyrighted (c) 1998 by and released under the GPL v2. Author: Alexander Kourakos <Alexander@Kourakos.com> Web: http://www.kourakos.com/~awk/pclock/ PCLOCK(1)
All times are GMT -4. The time now is 08:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy