File character adjustment based on specific character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File character adjustment based on specific character
# 1  
Old 05-29-2012
File character adjustment based on specific character

i have a reqirement to adjust the data in a file based on a perticular character

the sample data is as below

Code:
483PDEAN CORRIGAN     52304037528955WAGES                     50000
89BP                ABCD MASTER352         5434604223735428       4200 
58BP                SOUTHERN WA848        1270651700021            6735
72FTNO 1 ACCOUNT          20615130765473                           10000
86FTMRS CAROL ANN OWEN20295050971987                           20000

Steps i need to do
1)check if the character 3,4 are 'BP'
2) if yes then then move char 22 onwards 16 steps to left
3)then move chars from 28 onwards left by 6 steps
4)then go to position 30 and add 22 spaces

so the data looks like below
there can also be a better way of doing it instead of movin all data to left and later adding spaces

Code:
483PDEAN CORRIGAN     52304037528955WAGES                     50000
89BPABCD MASTER352   5434604223735428                             4200 
58BPSOUTHERN WA848  1270651700021                                  6735
72FTNO 1 ACCOUNT      20615130765473                               10000
86FTMRS CAROL ANN O  20295050971987                               20000

Moderator's Comments:
Mod Comment Please view this link: How to use [code]...[/code] tags

Last edited by Scrutinizer; 05-29-2012 at 08:03 AM.. Reason: code tags
# 2  
Old 05-29-2012
Code:
# awk '{if(substr($0,3,4)~"BP"){c=substr($0,21,22);$1=$1c;gsub("  ","",c);sub(" "c,"");$(NF-1)="  " $(NF-1);
$NF="                                " $NF}}1' file
483PDEAN CORRIGAN     52304037528955WAGES                     50000
89BPABCD MASTER352   5434604223735428                                 4200
58BPSOUTHERN WA848   1270651700021                                 6735
72FTNO 1 ACCOUNT          20615130765473                           10000
86FTMRS CAROL ANN OWEN20295050971987                           20000

This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

File Parsing based on a character in a specific field

Hi All, I'm having a hard time finding a starting point for my issue. I have a 30k line file (fspsec.txt) that I would like to parse into smaller files based on any character existing in field 1. ACCOUNTANT LEVEL 1 (ACCT.ACCOUNTANT) OPERATORS: DOEJO (418) TOOLS: Branch Maintenance ... (2 Replies)
Discussion started by: aahlrich
2 Replies

3. UNIX for Advanced & Expert Users

Replace certain character at specific place with related character

hello i have file with 100k records and each one has certain value that starts at 28th column and certain value that starts at 88th column e.g. 1st file <25>1234567 ..... <88> 8573785485 i have aditional file with values which are related to value that starts at 88th column of the... (1 Reply)
Discussion started by: dell1520
1 Replies

4. Shell Programming and Scripting

How to replace a character in a specific column in a file?

This is a file that I have test line 1 (55) ) test line 2 (45) ) I would like to change all the parens in position 1 of this file to a ); i only want to check position 1 in every line of the file. I have tried different varations of sed, but cannot seem to be able to limit it to... (1 Reply)
Discussion started by: JoeG
1 Replies

5. Shell Programming and Scripting

Delete line based on count of specific character

I'm looking for what I hope might be a one liner along these lines: sed '/a line with more than 3 pipes in it/d' I know how to get the pipe count in a string and store it in a variable, but I'm greedy enough to hope that it's possible via regex in the /.../d context. Am I asking too much? ... (5 Replies)
Discussion started by: tiggyboo
5 Replies

6. Shell Programming and Scripting

Help with replace character based on specific location

Hi, I got long list of reference file (column one is refer to the header in input file; column 2 is info of start position in input file; column 3 is info of end position in input file;) shown as below: read_2 10 15 read_3 5 8 read_1 4 10 . . . Input file (huge file with total... (6 Replies)
Discussion started by: perl_beginner
6 Replies

7. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

8. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

9. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

10. Shell Programming and Scripting

How to change a specific character in a file

Hi, I have a data file with following structure: a|b|c|d|3|f1|f2|f3 a|b|c|d|5|f1|f2|f3|f4|f5 I want to change this data to: a|b|c|d|3|f1;f2;f3 a|b|c|d|5|f1;f2;f3;f4;f5 Data in column 5 tells the number of following fields. All fields delimiter after the 5th column needs to be... (6 Replies)
Discussion started by: sdubey
6 Replies
Login or Register to Ask a Question