Visit Our UNIX and Linux User Community


sed command to replace multiple column in one go


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command to replace multiple column in one go
# 1  
Old 04-03-2017
sed command to replace multiple column in one go

Hi,

I want to replace the value in more than one column.
For one column ,following command is working -
Code:
sed 's/./$value_to_replace/$column number' file_name

Code:
e.g. suppose this is input 1111000000
command - sed 's/./M/5'
output= 1111M000000

For two column also command is like -
Code:
 cat file_name | sed 's/./M/5 | sed 's/./M/6'

But if I want to replace n value how to do that?

Thanks...
# 2  
Old 04-03-2017
HI,

Code:
sed 's/pattern_to_be_replaced/New_pattern/g' file_name

Regard's
Venkat


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 04-03-2017 at 07:24 AM.. Reason: Added CODE tags.
# 3  
Old 04-03-2017
Hello Preeti Chandra,

There are 2 things here.
I- Please DO NOT use cat Input_file | sed ...... as sed ....... Input_file, it can read Input_file by itself.
II- To substitute all the occurrences of a string you should use sed 's/old_text/new_text/g with single sed only.

Just try it out and let us know how it goes then.

Thanks,
R. Singh
# 4  
Old 04-03-2017
My question is entirely different.
Code:
Input-sequence of binary number(it a file contains multiple values)
from this sequence I want to change some particular column for each input

I have to change some value in the input after that this substitute command .
But above two commands are working fine but I want to change 10 columns in one input ,how to do that??
# 5  
Old 04-03-2017
Quote:
Originally Posted by Preeti Chandra
My question is entirely different.
Code:
Input-sequence of binary number(it a file contains multiple values)
from this sequence I want to change some particular column for each input

I have to change some value in the input after that this substitute command .
But above two commands are working fine but I want to change 10 columns in one input ,how to do that??
Hello Preeti,

I think whatever was asked in your post I had tried to answer it, Without letting us know what is sample Input_file and expected output with all conditions by which you want to get the expected result how we could help you? Kindly do help us by providing all details to help you.

Thanks,
R. Singh
# 6  
Old 04-03-2017
Input file -
Code:
000000011111111000000000111111110000000011111111000000001111111100000000111
000000111101101010010000001101011110100011110010101100101001101000110011110
100110101111100101001010111001010001000011000001000000010000110111010010100
110001101100111110110111100010101001101011010011111100010010000010110101000
101110111101100111111111101011100110111001100111001001110011000010010110000
110001001011111111100000001111011000011000001001010010010110010011100111011
110011111101010001010111011101000110001001111110010111111110010110001100001
100111101100001000010011011011110000001100011011101101101000101100011110010
010111001000110000101101010101100100011000001101100101011111001000001010000
000001111000010100111010010101010100110000010010111011011000011101000000010
110110000011000111010000101111011000100000010100001100100111001000111010011
000100011011100011100111100011001000011100001100010011000111000111101010010
100010100001111101100001010101010011000001001100001000111010011111110111110
000110001111100000100001110010110110111001111110101000010001000001111011010
001101011001001101000010010100011100001000000101000010110000000000111010000
010101111000001111111101111000011000111000011000001110000001111110001101100
100000011010111100111101001100100100111000000001011100010111001010011000100
011111100110101011101001111111010011001001000010111000101110111101011010011
111001001101001101010000000101000011001001011110010111100100111000000001101
111110011010111100111010111000010001111011101110101010101111000000111111000
100010010011010010100100011110000011010001001000010010000100011000111101110
001010000001101101010000100010111110100001101111111011111110101101000110001
001101101100100110011011100001110111011001010100010101000101111110100001111
111111001001000000010011111000011010011001011001100111011101110001011101110
111000101000000011101110101001111100000000010000100001000110001011000010110
100000101101100010001000011000111000010000001011101111100101100001100000000
001111110000101000010110110001010000101000001000110010001110001011001111011
010010100001000111011011101001010110000001111010111101110101100110100001111
111001111001110010101110011100111011101001010110000101100001001100101000001
110001111001000111011101101010001011000001000001000000010011100001100110001
111100111110000000011100010101110001010011001110000011100000000111001100110
010101100000001111000111111010011010100001000000001111101101010111001010111
111000000101110101011100001101111001001011000010010000100111010110001110100
110000111110101000011001001001011011111001011110100111101001100111000010010
100101000000101000010010011000000011000001000011000000110011011010010000110
000001001010000100000001000001000000011000010001100100011001101110101010100
110011011101010111011000110111101000010100011100110111001110011101110110110
001011011001001010001100010101011010000001000001011010010110111111011000000
100111010100100010010010001101111100101000000100011001000101000100001110110
101000101110110010010001011011000000110100000010011101001011000110100000001
110011100001011001010110011000101011111001000101010001010101101100001011000
001101111111010100010100010010101000001100000001000000010010010011010001101
111101001000001001110100111011110011001001011101100111011010100011011110010
101001000010101111001100001111111100001000001100100011001010101101100011100
010110110011000111001100100000101010001001010111011001000011100000001001011
101010110100001111110000111101011100101000010000111100110111000000100011001
001011001010100110101000001100101010010001000000101000000010111001010001100
000000111010001011100010011101100011101001000001010000010111010110011100110
011010111000000111101010100000100100010000001100001010011111100000110010011
011100111010110101100100100010010011000001010100001101000000010100110101100
110011101110010010100010111001111010011001011101111011011010001010100101111
001000101101111011110110001011010111100001000011111001000010000010010001100
011101101100110100101101111111001001101011011110101100011001010100101110010
000111011001010010101101101001110011010001010110110101101110001100000110111
100011011101110001011111000000010100011000011000000011110101111000010111001
001101011101001100100000000101000010011001001010000000001001011110010100011
000001010011011010111010110001110010010001000100011011101011000101110010111
011101100100110011110011011001100000111000001100100011001000001011101000011
001010000001000101101111110110100000101100011101001000001101110100001011010
011101010010101111010001000101010000101000000100101100010100000000011010000
101010111000010010110001011011110100011000011010101011001011011101011111110
010000011110101000001001101100110100000000010111111110000010110010111100110
010101001101100011111101011111000001111011110011100100111011101001011101100
010010111100100001100010100000000111101110011111110111011000100100000010011
011101101001101100010000011000101100011000000011010000110100111110011111110
111011011010111110111000110101011111111001001000001111011001111110010101101
101110010010010101111010111100101011010001011100110111001101111110110011100
101111111001011001010010010001100111000001001100101011001011011001111110100
101101000100100011011011110011111001010011110100010101000100100101101010011
000010000010110000101011011000010010001001001000001100100101010010010110100
010011101111111111001010011010010110101001110110111101101101000100011100000
001011110011101010000001101100001000111000000100001110001111111001100101010
101101110011111111110101110111010110110011100110000001100011110001011001000
010110010111011111011000110100000100001000001000110010001100110110001001010
001001001111100101010101100101000110110001110110101101101011001101011101110
011101000100100101111011001001010011000001000010000000100011000001100111110
110010100000010101101001101101001011100001000010011000001101101100010111100
101100101101110100011001100110110111011001011011000110110000101100110101011
100111111101011111100101100111111001110011001111101110010010001011101010011
011010100110000110001111001101101110111011110000111110011100100001110110011
111110000011000000111011011011001000101100011001100110011010110111111010100
111101110101110100101010100110001000001000011110010111100111010010111001001
101011000110000111001100000111001000100100010010000100100011011110100010100
111001111100000000111110010101111110011001111010001110001110000011110100000
001110010000111110001110001011000100110000001011100010111010101011010101100
000111101110000101011110110001011100111000000110000100101011011001001001100
010101100000110000100001011111000110100011111111100111111001000000101001110
000011111010001000101010100111000000100000000101100001011010100011001000110
000111110010001101101101111000101011100001010101011111011100011110100000100
010000100101111100011000100001010000110000001011110010111100000101000100100
011001001001011010100101011000011010010001000000100100001000001111101111011
001011110101011011111001011011000100111000001100001010101001111101100000100
010010010100010110001001110100000011110001010110111011011011000100011010110
011101000011001011011001010000111111100001000000110000001111101011010000010
010010100101001011001101001010100000011100011101100111011000011000010100000
010011000011011001000011111111001100001000011111010111110110110110100111100
000001001110111010110011000001101111000001001001010010010110111100000100001
110111100011110100010011010100111011101001001001100010011000010011100111011
001110110111111001110000011110010101100001011111110111111101111101000001010
101100110000011000011100000100100100100000001010010010100110101100111001010
111011000111011000100110001010000010100001000100000010110110100001101111110
011100001100010001011101100000111000000000001111110011111110101101110100010
010000010111101000110000001010101110000001110101011000011101011000010110000
100011001010011101111011010110000110011001101101111011011100111100010100110
001010111100011100101101001110100001000011100011001000110001010101101010000
011111001000101110101111011100000001001011010111000101110010010111100011100
000001101010101010011010100010111110001001111101110111011111111100111011111
000100000100000001111111000011110011110001010111101101111011101011010101100
110101011001010001010001001001010001100011000101100001011001101001110010000
111001011110010010100110011001100100101000010001101001010111110111111011100
000001011011111000011100110001111100011000010100110101001101100101111011000
010100110010011000000001000010001011111001000100010001000100011010111011010
110000110011001110011110110110111100011000011001001110010000110110010101001
111111101011000110100111000100001001111011011111010111110110111010101100101
000101101011010001100000101110001011001001001000101010001001110100010010101
000001100011010001010110001000100000001000010100110101001110110100011000010
100001111000011101001001001001100110000001101001011111010000011101111100000
001000010010101100010101010101101001111011000000011010111101000000111101110
011011111000110111110010101010011110101011100001000000010001110001010100100

output - for one input likewise i want for all values present in the input file
Code:
011011111MMMMMMMMMM10010101010011110101011100001000000010001110001010100100

# 7  
Old 04-03-2017
Hello Preeti,

Not much clear, suspecting that you need to substitute string 011011111 to 011011111MMMMMMMMMM then following may help you in same.
Code:
sed 's/011011111/011011111MMMMMMMMMM/g'  Input_file

Thanks,
R. Singh

Previous Thread | Next Thread
Test Your Knowledge in Computers #343
Difficulty: Medium
Scott McNealy, Andy Bechtolsheim, and Vinod Khosla, all Caltech graduate students, founded Sun Microsystems.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract a column and multiple by 1000 and replace it on same file

Hi All, I need to extract a position in the file and multiple the value by 1000 and the replace it . Original 0010001200084701217637306521200000000000010010000000 ---> 000847 * 1000 0010012700086001213437404323000000000000001001000000 ---> 000860 * 1000... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

2. Shell Programming and Scripting

sed command to replace one value which occurs multiple times

Hi, My Input File : "MN.1.2.1.2.14.1.1" := "MN_13_TM_4" ( 000000110110100100110001111110110110101110101001100111110100011010110111001 ) "MOS.1.2.1.2.13.6.2" := "MOS_13_TM_4" ( 000000110110100100110001111110110110101110101001100111110100011010110111001 ) Like above template,I have... (4 Replies)
Discussion started by: Preeti Chandra
4 Replies

3. Shell Programming and Scripting

How to search and replace string in column in file with command sed?

how to search and replace string in column in file with command sed or other search "INC0000003.in" and replace column 4 = "W" $ cat file.txt INC0000001.in|20150120|Y|N|N INC0000002.in|20150120|Y|N|N INC0000003.in|20150120|Y|N|N INC0000004.in|20150120|Y|N|Noutput... (4 Replies)
Discussion started by: ppmanja3
4 Replies

4. Shell Programming and Scripting

Search and replace multiple patterns in a particular column only - efficient script

Hi Bigshots, I have a pattern file with two columns. I have another data file. If column 1 in the pattern file appears as the 4th column in the data file, I need to replace it (4th column of data file) with column 2 of the pattern file. If the pattern is found in any other column, it should not... (6 Replies)
Discussion started by: ss112233
6 Replies

5. Shell Programming and Scripting

Awk: Multiple Replace In Column From Two Different Files

Master_1.txt 2372,MTS,AP 919821,Airtel,DL 0819,MTS,MUM 919849788001,Airtel,AP 1430,Aircel MP,20 405899143999999,MTS,KRL USSDLIKE,MTS,DEL Master_2.txt 919136,DL 9664,RAJ 919143,KOL 9888,PUN Input File: (4 Replies)
Discussion started by: siramitsharma
4 Replies

6. Shell Programming and Scripting

Sed/awk/perl command to replace pattern in multiple lines

Hi I know sed and awk has options to give range of line numbers, but I need to replace pattern in specific lines Something like sed -e '1s,14s,26s/pattern/new pattern/' file name Can somebody help me in this.... I am fine with see/awk/perl Thank you in advance (9 Replies)
Discussion started by: dani777
9 Replies

7. Shell Programming and Scripting

sed multiple replace

Hello! I'm using sed to perform a lots of replaces in one text file. I call it this way: sed -f commands.txt in.txt > out.txt commands.txt has about 1000 lines, each one is some variation of: s/from/to/gI And in.txt has about 300 000 lines. So the problem is that operation takes about... (7 Replies)
Discussion started by: backdrift
7 Replies

8. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

9. Shell Programming and Scripting

awk/sed column replace using column header - help

$ cat log.txt Name Age Sex Lcation nfld alias xsd CC 25 M XYZ asx KK Y BB 21 F XAS awe SS N SD 21 M AQW rty SD A How can I replace the column with header "Lcation" with the column with header "alias" and delete the "alias" column? so that the final output will become: Name Age Sex... (10 Replies)
Discussion started by: jkl_jkl
10 Replies

10. Shell Programming and Scripting

using sed command to replace multiple lines

the file contains the follwoing lines /* * Copyright (C) 1995-1996 by XXX Corporation. This program * contains proprietary and confidential information. All rights reserved * except as may be permitted by prior written consent. * * $Id: xxx_err.h,v 1.10 2001/07/26 18:48:34 zzzz $ ... (1 Reply)
Discussion started by: radha.kalivar
1 Replies

Featured Tech Videos