sed changes by column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed changes by column
# 1  
Old 01-11-2011
sed changes by column

Is it possible to make changes with the sed command in a specific column only?
If yes, how?
If not, how could I do that instead?
Thanks!

---------- Post updated at 02:01 PM ---------- Previous update was at 01:39 PM ----------

e.g.
Group1 Group2_3_1 1_2_3_4_5_
I would like to have as a result:
Group1 Group2_3_1 12345
# 2  
Old 01-11-2011
In awk:
Code:
$ cat file
Group1 Group2_3_1 1_2_3_4_5_

$ awk '{gsub("_", "", $3)}1' file
Group1 Group2_3_1 12345

This User Gave Thanks to Scott For This Post:
# 3  
Old 01-11-2011
Thanks.
What is the function of the last 1 in your command? I tried to put a 2 there instead but the results look the same.
# 4  
Old 01-11-2011
It's an expression that would always evaluate to "true" (as would 2 (but 0 would not)), thus performing the default "action", which in awk is to print the line. So, it's shorthand for { print }. I think I will stop using it Smilie
This User Gave Thanks to Scott For This Post:
# 5  
Old 01-11-2011
Do you know a really good awk tutorial?Cheat Sheet? or anything useful to work with by any chance?
# 6  
Old 01-11-2011
Just use a search engine. There are many.

awk tutorial
awk cheat sheet
# 7  
Old 01-11-2011
Obviously I have done that already but haven't found one that I really like and would recommend to someone else.
 
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. UNIX for Beginners Questions & Answers

sed A Value In A Column

trying to replace a specific value in a column with sed. this is what I have but can't get it to work, replace dog with kitty if dog is in the 3rd column and bunny in the 1st column if bird is there bird lizard fish bird lizard dog bird lizard fishsed '/bird/s/^/bunny/1;'/dog/s/^/kitty/3'... (3 Replies)
Discussion started by: jimmyf
3 Replies

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

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

5. UNIX for Dummies Questions & Answers

Printing a particular column using SED

Hi, i want to display only the particular column using SED command. For example, ps -ef|grep ash |sed -n '1p'|cut -d ' ' -f2   this gives 29067 ps -ef|grep ash |sed -n '1p'|awk '{print $2}'    this also gives the same  in the same way i need the solution using sed. Please... (4 Replies)
Discussion started by: pandeesh
4 Replies

6. Shell Programming and Scripting

use sed on only column $3 with awk

I am using the command ls -lhB --group-directories-first --no-group --file-type --time-style=+%D $@ | sed 's/AlphaLexman/ALM/g' to replace my username with my initials (to keep the width shorter), but if my username is in the filename such asreport_by_AlphaLexman.txtit becomesreport_by_ALM.txt ... (2 Replies)
Discussion started by: AlphaLexman
2 Replies

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

8. Shell Programming and Scripting

Can SED Search By Column?

Hi all, I am trying to search for a keyword in the fourth column of a massive carrot(^) delimited file and unfortunately I cannot use AWK (which would have been ideal). Can SED (or maybe even GREP) perform a search like this? (12 Replies)
Discussion started by: Korn0474
12 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. UNIX for Dummies Questions & Answers

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 Replies)
Discussion started by: rexmabry
2 Replies
Login or Register to Ask a Question