Paste value at specific column using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Paste value at specific column using sed
# 1  
Old 12-01-2009
Paste value at specific column using sed

Hi

I want to paste some value at specific column in a file using sed.
say I want to add "Welcome to UNIX" from column 300 onwards in a file using sed.

How to do it .

---------- Post updated at 11:18 AM ---------- Previous update was at 11:09 AM ----------

Adding more information :
I am using this command
Code:
sed "s/$/$var1$var2/g" $FILE

However it is appending at the end of each line.
I want to append it from column 300 onwards.

Instead of $ can I specify column from which I want.
# 2  
Old 12-01-2009
Code:
 $sed "s/.\{300\}/&Welcome to UNIX/g" FILE

# 3  
Old 12-01-2009
Hi
Thanks for your reply.

I am trying this :
Code:
sed "s/.\{300\}/$var1$var2/g" $FILE

However , it is not working.
It is giving error :

Code:
sed: Function s/.\{300\}/100200/g cannot be parsed.

# 4  
Old 12-01-2009
Code:
I tried like this, 

## Sample file
$ cat a
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

$ cat t.sh

var1=100
var2=200

sed "s/.\{300\}/&$var1$var2/g" a

## see 100200 in output

$sh t.sh
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789010020012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

# 5  
Old 12-01-2009
If in my file data is till 280 column only and I want to add content at 300 column .
Will this still work ?
# 6  
Old 12-01-2009
make clear definition of the word column. column to some may mean fields delimited by some character(s). ie, field 300. Or are you talking about "character position 300 onwards" ?
# 7  
Old 12-01-2009
I mean character position 300 onwards...
And my file is having data only at 280 character position.
I want to add values from 300 character position onwards.

I am trying this :
Code:
sed "s/.\{300\}/$var1$var2/g" $FILE

However it is not working.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

2. Shell Programming and Scripting

sed or awk to remove specific column to one range

I need to remove specific column to one range source file 3 1 000123456 2 2 000123569 3 3 000123564 12 000123156 15 000125648 128 000125648 Output required 3 000123456 2 000123569 3 000123564 12 000123156 15 000125648 128 000125648 (6 Replies)
Discussion started by: ranjancom2000
6 Replies

3. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

4. Shell Programming and Scripting

Problems with awk (fatal error) and paste (two variables into one column-by-column)

Hello, I have a script extracting columns of useful numbers from a data file, and manipulating the numbers with awk commands. I have problems with my script... 1. There are two lines assigning numbers to $BaseForAveraging. If I use the commented line (the first one) and let the second one... (9 Replies)
Discussion started by: vgbraymond
9 Replies

5. Shell Programming and Scripting

awk or sed to find specific column from different files

Hi everybody, I have a folder with many files: Files with 8 columns: X 123 A B C D E F And files with 7 columns: X1234 A B C D E F I am trying to find a way to extract the 5th column when the files have eight columns, or the 4th column when the files have... (3 Replies)
Discussion started by: Tzole
3 Replies

6. UNIX for Dummies Questions & Answers

Excluding a specific column from sed replacement

Hi, I would like to replace all 0's to 1's throughout my text file. However I do not want column 3 altered. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

7. UNIX for Dummies Questions & Answers

Use sed to replace but only in a specific column of the text file

Hi, I would like to use sed to replace NA to x ('s/NA/x/g'), but only in the 5th column of the space delimited text file, nowhere else. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

8. Shell Programming and Scripting

Can sed be used to insert data at specific column?

I'm trying to use sed to insert data at a specific column, let's say my data looks like this: 0553 1828 0552 1829 0550 1829 0549 1830 0548 1831 what I want is this: timein 0553 timeout 1828 timein 0552 timeout 1829 timein 0550 timeout 1829 timein 0549 timeout 1830 timein 0548... (5 Replies)
Discussion started by: mswartz
5 Replies

9. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

10. Shell Programming and Scripting

oneliner:sing SED on a specific column

is this possible a one liner sed command. I have a text file ex. from : xxx yyy ZZZ /test/devl/aasdasd.log1 xxx yyy ZZZ /test/devl/aasdasd.log2 to : xxx yyy ZZZ /test/prod/aasdasd.log1 xxx yyy ZZZ /test/prod/aasdasd.log2 and I want to sed only the fourth column sed 's/devl/prod/g' ... (8 Replies)
Discussion started by: chaseeem
8 Replies
Login or Register to Ask a Question