Change one column using sed??


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Change one column using sed??
# 1  
Old 03-27-2008
Change one column using sed??

Is there way to use sed to change only one occurence in a colon separated line?

I would like to change a file from

*:*:rex:rex
*:*:simon:rex


to

*:*:rex:mabry
*:*:simon:rex
# 2  
Old 03-27-2008
In this case, anchoring to end of line would seem to work fabulously. In the general case, you have to come up with a regular expression which indicates where in the line you want the substutution to happen, obviously.
# 3  
Old 03-27-2008
Hi.

I try to match the tool to the problem. Whenever I encounter a situation that deals with delimited columns or fields, I reach for awk, because awk makes it so easy to deal with such structures.

As era said, if you're dealing with the last field (or the first field), then sed can work, but trying to manipulate a field in the middle is where awk will shine. It may seem like awk is a difficult tool to learn, but you can start with simple constructs. Look at a few of the posts here, or Google for awk tutorial for lots of hits.

This forum has an abundance of folks who are well-versed in awk, and are willing to help. To get help, you need only to show what you have tried and how it failed ... cheers, drl

Last edited by drl; 03-29-2008 at 02:56 PM.. Reason: Re-worded clumsy sentence.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk/sed summation of one column based on some entry in first column

Hi All , I am having an input file as stated below Input file 6 ddk/djhdj/djhdj/Q 10 0.5 dhd/jdjd.djd.nd/QB 01 0.5 hdhd/jd/jd/jdj/Q 10 0.5 512 hd/hdh/gdh/Q 01 0.5 jdjd/jd/ud/j/QB 10 0.5 HD/jsj/djd/Q 01 0.5 71 hdh/jjd/dj/jd/Q 10 0.5 ... (5 Replies)
Discussion started by: kshitij
5 Replies

2. Shell Programming and Scripting

Solution for replacement of 4th column with 3rd column in a file using awk/sed preserving delimters

input "A","B","C,D","E","F" "S","T","U,V","W","X" "AA","BB","CC,DD","EEEE","FFF" required output: "A","B","C,D","C,D","F" "S", T","U,V","U,V","X" "AA","BB","CC,DD","CC,DD","FFF" tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
Discussion started by: khblts
5 Replies

3. Shell Programming and Scripting

Change Lines into column

Hello how can I change lines into column? e.g. I have a Text file which looks like: Surename...... Address..... Phonenumber..... Zipcode.. Surename... Address.... Zipcode Surename... I want that Surename is in column 1 and every following line should be in additional colums.... (5 Replies)
Discussion started by: witchblade
5 Replies

4. Shell Programming and Scripting

Change column to row base on column 2

Hi Guys, Input.txt L194 A -118.2 L194 B -115.1 L194 C -118.7 L196 A 0 L196 C 0 L197 A -111.2 L197 B -118.9 L197 C -119.9 L199 A -120.4 L199 B -119.9 ... (2 Replies)
Discussion started by: asavaliya
2 Replies

5. Shell Programming and Scripting

awk or sed: change the color of a column w/o screwing up column spacing

Hey folks. I wrote a little awk script that summarizes /proc/net/dev info and then pipes it to the nix column command to set up column spacing appropriately. Here's some example output: Iface RxMBytes RxPackets RxErrs RxDrop TxMBytes TxPackets TxErrs TxDrop bond0 9 83830... (3 Replies)
Discussion started by: ryran
3 Replies

6. Shell Programming and Scripting

Change file content 4 column to one Column using script

Hi Gurus, I have file content sample: ,5113955056,,TAgent-Suspend ,5119418233,,TAgent-Suspend ,5102119078,,TAgent-Suspend filenames 120229H5_suspend, 120229H6_unsuspend I receive those files one of directory /home/temp/ I need following: 1. Backup first /home/temp/ file to... (5 Replies)
Discussion started by: thepurple
5 Replies

7. Shell Programming and Scripting

Change value in a column

Hello! Please could anyone help me in writing a code to modify the value in column two of a file with more than two tab-separated column (but the lines may have a different number of columns, i.e. more or less columns), according to the following conditions. When the value of column two is... (5 Replies)
Discussion started by: mjomba
5 Replies

8. Shell Programming and Scripting

Awk or Sed, fubd match in column, then edit column.

FILE A: 9780743551526,(Abridged) 9780743551779,(Unabridged) 9780743582469,(Abridged) 9780743582483,(Unabridged) 9780743563468,(Abridged) 9780743563475,(Unabridged) FILE B: c3saCandyland 9780743518321 "CANDYLAND" "MCBAIN, ED" 2001 c3sbCandyland 9780743518321 ... (7 Replies)
Discussion started by: glev2005
7 Replies

9. Shell Programming and Scripting

Change names in a column based on the symbols in another column

If the 4th column has - sign then the names in 3rd column has to change to some user defined names (as shown in output). Thanx input1 1 a aaaaa + 2 b bbbbb + 3 c ccccc + 4 d ddddd + 5 e eeeee + 6 f xxxxx + 8 h hhhhh +... (8 Replies)
Discussion started by: repinementer
8 Replies

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