use sed on only column $3 with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting use sed on only column $3 with awk
# 1  
Old 02-10-2011
use sed on only column $3 with awk

I am using the command
Code:
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 as
Code:
report_by_AlphaLexman.txt

it becomes
Code:
report_by_ALM.txt

Is there any way to get sed to only look at the third column in my 'ls' output and not the sixth column. I think I need to use
Code:
awk '{ print $1 $2 sed_something_$3 $4 $5 $6 }

but I am a complete noob with awk!

Original output:
Code:
-644. 1 AlphaLexman 124K 02/08/11 report_by_AlphaLexman.txt

Actual output:
Code:
-644. 1 ALM 124K 02/08/11 report_by_ALM.txt

Desired output:
Code:
-644. 1 ALM 124K 02/08/11 report_by_AlphaLexman.txt

NOTE: I have some other sed's to replace the -rw-r--r--. to -644.
# 2  
Old 02-10-2011
To replace only the first occurrence you should omit the global option:
Code:
sed 's/AlphaLexman/ALM/'

instead of:
Code:
sed 's/AlphaLexman/ALM/g'

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 02-10-2011
Thank you very much, I was making the problem bigger than the solution.
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

Using sed in awk column

Hello, I need to translate a file with more thousand lines like thiszoneobjectrename "AAA_to_BBB"in a lineszoneobjectrename "AAA_to_BBB","AAA_BBB" I tried to using awk and sed in this manner but it don't workgrep _to_ Documenti/zoneSWITCH2 |awk '{print "zoneobjectrename " $2 "," $2= sed... (7 Replies)
Discussion started by: alen192
7 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

Using awk/sed to determine whether there are any 2's, 3's and 4's in a column

Hi, I have a very large file which is of the general format: 0 3 4 2 ... 3 2 4 0 ... 0 3 4 2 ... 3 0 4 2 ... . . . . ... . . . . ... I would like to apply a simple awk/sed script to work out whether there are any 2's, 3's and 4's in each column. The results would look as... (3 Replies)
Discussion started by: kasan0
3 Replies

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

7. Shell Programming and Scripting

Deleting the first column with sed,awk or perl

336 brtr 256 hello Output: brtr hello How can i do this with sed,awk or perl? (5 Replies)
Discussion started by: cola
5 Replies

8. Shell Programming and Scripting

Remove certain parameters from column using awk or sed

I have a text file Nov 1 LOG_10_000000343.gzip_COMPLETE 2910 server.log.3 Nov 4 LOG_10_000000343.gzip_COMPLETE 2910 server.log.4 Dec 5 LOG_10_000000343.gzip_blah 2910 server.log.5 Jul 6 LOG_10_000000343.gzip_ERROR 2910 server.log.1 I need to convert this to Nov 1 LOG_10_000000343.gzip... (3 Replies)
Discussion started by: gubbu
3 Replies

9. Shell Programming and Scripting

sed/awk-adding numeric to a column

I have a txt file as follows Code: Oct 1 file1 4144 Oct 1 file23 5170 Oct 2 file5 3434 Oct 21 file56 2343 I need to add a new column by marking the right log file from current directory. For example populate like this. Please not in the second columt for "1" it has... (2 Replies)
Discussion started by: gubbu
2 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