oneliner:sing SED on a specific column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting oneliner:sing SED on a specific column
# 1  
Old 07-15-2008
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' awk '{print $4}' text
# 2  
Old 07-15-2008
Code:
sed 's/xxx yyy ZZZ \/test\/devl/xxx yyy ZZZ \/test\/prod/'

# 3  
Old 07-15-2008
HI thanks for the reply, columns 1,2,3 are not constant.. thats why I only need to run sed on the fourth column.

below is a better example, for you to better understand the situation.
now we need to run sed on column3

FROM
mv /prod/system/system.db2 /prod/system/system.db2
mv /prod/system/tbs_data.db2 /prod/system/tbs_data.db2

TO
mv /prod/system/system.db2 /devl/system/system.db2
mv /prod/system/tbs_data.db2 /devl/system/tbs_data.db2

Last edited by chaseeem; 07-15-2008 at 05:21 AM.. Reason: edited
# 4  
Old 07-15-2008
This sufficient?

Code:
echo "mv /prod/system/system.db2 /prod/system/system.db2"| sed 's!\/prod\/!\/devl\/!2'
mv /prod/system/system.db2 /devl/system/system.db2

# 5  
Old 07-15-2008
Code:
echo "mv /prod/system/system.db2 /prod/system/system.db2" | sed 's/\([a-z]*\) \([0-9a-z/.]*\) \/prod/\1 \2 \/devel/'
mv /prod/system/system.db2 /devel/system/system.db2

# 6  
Old 07-15-2008
Quote:
Originally Posted by chaseeem
HI thanks for the reply, columns 1,2,3 are not constant.. thats why I only need to run sed on the fourth column.

below is a better example, for you to better understand the situation.
now we need to run sed on column3

FROM
mv /prod/system/system.db2 /prod/system/system.db2
mv /prod/system/tbs_data.db2 /prod/system/tbs_data.db2

TO
mv /prod/system/system.db2 /devl/system/system.db2
mv /prod/system/tbs_data.db2 /devl/system/tbs_data.db2

How about this,

Code:
sed 's/prod/devl/2' filename

Regards,
Chella
# 7  
Old 07-15-2008
Quote:
Originally Posted by chaseeem
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' awk '{print $4}' text
why must it be a sed one liner? anyway for your problem, its easier to work with fields
Code:
awk '$4 ~ /dev/{gsub("devl","prod",$4}1' file

use the more suitable tool for the job
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. UNIX for Dummies Questions & Answers

deleteing duplicate lines sing uniq while ignoring a column

I have a data set that has 4 columns, I want to know if I can delete duplicate lines while ignoring one of the columns, for example 10 chr1 ASF 30 15 chr1 ASF 20 5 chr1 ASF 30 6 chr2 EBC 15 4 chr2 EBC 30 ... I want to know if I can delete duplicate lines while ignoring column 1, so the... (5 Replies)
Discussion started by: japaneseguitars
5 Replies

7. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 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

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

10. 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
Login or Register to Ask a Question