Replacing certain positions in lines with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing certain positions in lines with spaces
# 1  
Old 10-06-2017
Replacing certain positions in lines with spaces

Hello,

I have a file with hundreds of lines. Now I need to replace positions 750-766 in each line (whatever there is there) with spaces... how can I do that?

Which command to use?

The result will be all the lines in the file will have spaces in positions 750-766.

Thanks!
# 2  
Old 10-06-2017
Try
Code:
sed 's/\(.\{749\}\).\{17\}/\1                 /' file

# 3  
Old 10-09-2017
why 749 when I wanted 750-766?

and after I pasted the command is says:
"cannot be parsed."

Any suggestions?

Thanks.
# 4  
Old 10-09-2017
Quote:
Originally Posted by netrom
and after I pasted the command is says:
"cannot be parsed."
Not sure why, the command seems to be correct. What is your OS and version?

Quote:
Originally Posted by netrom
why 749 when I wanted 750-766?
Good question: when you want to change "from position 750" that means that the first 749 characters in the line should go unchanged. What RudiC does is to read each line up to character 766 in two parts: the first 749 characters and then 17 characters. The first part is then put to output unchanged (the "\1", which is a so-called "back-reference"), the second part is replaced by 17 blanks.

I hope this helps.

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

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter lines based on values at specific positions

hi. I have a Fixed Length text file as input where the character positions 4-5(two character positions starting from 4th position) indicates the LOB indicator. The file structure is something like below: 10126Apple DrinkOmaha 10231Milkshake New Jersey 103 Billabong Illinois ... (6 Replies)
Discussion started by: kumarjt
6 Replies

2. Shell Programming and Scripting

Replacing tabs with spaces

I want my program to replace tabs with spaces.1tab=4spaces.When i write aa(tab)aaa(tab)(tab)a(tab) it must show me aaxxaaaxxxxxaxxx. I think that my program works corectly but when a write aaa(tab)a it must show aaaxa but it is aaaxxxxxa.Please for help!!! That is my code: #include <stdio.h> ... (3 Replies)
Discussion started by: marto1914
3 Replies

3. Shell Programming and Scripting

awk script replace positions if certain positions equal prescribed value

I am attempting to replace positions 44-46 with YYY if positions 48-50 = XXX. awk -F "" '{if (substr($0,48,3)=="XXX") $44="YYY"}1' OFS="" $filename > $tempfile But this is not working, 44-46 is still spaces in my tempfile instead of YYY. Any suggestions would be greatly appreciated. (9 Replies)
Discussion started by: halplessProblem
9 Replies

4. Shell Programming and Scripting

Replacing the new character with spaces

Hi Experts, We are facing some while loading the "csv" file to target table.Some of the records are having values as : Account number,Name,Address "123","XYZ","302 Street,Washington,US" "456","PQR"," 3233 Some Street, Washington,US" In the above file instead reading only two records it... (11 Replies)
Discussion started by: Amey Joshi
11 Replies

5. Shell Programming and Scripting

trim spaces and replacing value

Hi, I have a file origFile.txt with values: origFile.txt .00~ 145416.02~ xyz~ ram kishor ~? ~ ~783.9 .35~ 765.76~ anh reid~ kelly woodburg ~nancy ~ ~? Now each row in the file has value for 7 columns with "~" as delimiter. The requirement was i)I need to erase the blank spaces between... (2 Replies)
Discussion started by: badrimohanty
2 Replies

6. Shell Programming and Scripting

awk modifying entries on 2 lines at 2 positions

Hi this script adds text in the correct place on one line only, in a script. awk 'BEGIN{ printf "Enter residue and chain information: " getline var < "-" split(var,a) } /-s rec:/{$7=a; } {print}' FLXDOCK but I need the same info added at position 7 on line 34 and... (1 Reply)
Discussion started by: gav2251
1 Replies

7. UNIX for Dummies Questions & Answers

Replacing the Spaces

Hi, i have a tab dilimeted file.The records are :header is having column names.I am facing the following issue : I want to convert the spaces only for header file into "_" in the unix shell but the problem is that if i use sed command all the blank spaces are getting replaced by "_". For... (3 Replies)
Discussion started by: Amey Joshi
3 Replies

8. UNIX for Dummies Questions & Answers

Exclude lines which have blanks at certain positions

Hi All, I am getting a input file which doesnt have a field seperator. The file is being sorted on certain positions say from 0.55 to 0.59. If there are any blanks from 0.55 to 0.59 they will be listed as first set of records. I am not sure abt the number of records which will have blanks at... (8 Replies)
Discussion started by: helper
8 Replies

9. Shell Programming and Scripting

need help in replacing spaces in a file

hi all this is the part i am facing a problem eg data: filename : tr1 + T 40 this is a sample record in that file ... the value of T can be anything, but will be a single character. i need to cut from field two, and i am using this command cut -d " " -f2 tr1 >tr3 and the o/p is ... (7 Replies)
Discussion started by: sais
7 Replies
Login or Register to Ask a Question