sed command to edit fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command to edit fields
# 1  
Old 01-20-2008
Data sed command to edit fields

Hi, I'm a newbie to sed and I'm having trouble working with sed and fields.

Suppose I have a text file with:

AAA RFG:$2.10:6:25Oct06
WDD GGTR:$3.50:5:25Oct06
ADDSJ OO:$1.37:3:26Oct07
UGBDN S:$4.73:1:27Oct06
USY ADC:$2.38:20:27Oct06

And I want to substitute field 2 of line 3 with, say, $2.33. So that my output would be:

AAA RFG:$2.10:6:25Oct06
WDD GGTR:$3.50:5:25Oct06
AAA RFG:$2.33:3:26Oct07
UGBDN S:$4.73:1:27Oct06
USY ADC:$2.38:12:27Oct06

Can someone help with this? Thanks in advance!
# 2  
Old 01-20-2008
use awk instead.
Code:
# awk -F":" 'NR==3{$2="$2.33"}1' OFS=":"  file

# 3  
Old 01-20-2008
With sed:

Code:
sed '3s/\([^:]*:\)[^:]*/\1$2.33/' filename


Last edited by radoulov; 01-20-2008 at 08:14 AM.. Reason: modified ...
# 4  
Old 01-20-2008
Ok, I got it to work. Thanks! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

edit sed command

how can i make this sed command run faster? sed '51000000,51347442!d' file and sed '51347442,$ !d' file File is a 9GB in size. it runs on sunos 5.10 and linux red hat 6 servers and i use bash. (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

need to store query output fields in variables edit them and update the same in tables.

Hi , I have a query like select err_qty,drop_qty,unbld_qty,orig_qty from usage_data; I need to store the values of these fetched fields in variables, Need to edit them and update the new values into the table. Can anyone please help me in writing this piece of code:( (1 Reply)
Discussion started by: Rajesh Putnala
1 Replies

4. Shell Programming and Scripting

How to Use Sed Command to replace white spaces with comma from between two fields - Mayank

SHELL SCRIPT Hi I have a file in the following format Mayank Sushant Dheeraj Kunal ARUN Samir How can i replace the white space in between and replace them with a comma?? The resultant output should be Mayank,Sushant Dheeraj,Kunal ARUN,Samir i tried using sed -e... (8 Replies)
Discussion started by: mayanksargoch
8 Replies

5. Shell Programming and Scripting

edit fields awk

Hi there, i need some help please... I have this text, it's name data.txt that contains the following information: Mark Owen: 6999999888 6999999888 +302310999999 2310999999 Steve Blade Pit: +30691111222 2310888777 6999999888 John Rose: 2310777555 310544565 +302310999999 Mary Stuart:... (7 Replies)
Discussion started by: Mark_orig
7 Replies

6. Shell Programming and Scripting

Conditional edit for a field using sed

Hi I want to repalce a field in a txt file on solaris with say 100 records and each record having a total of 10 fields separated by a ~ . based on the following condition the record should be edited or else the record should be written as it is to a if the seventh field is 'XX' and if... (2 Replies)
Discussion started by: acharania2011
2 Replies

7. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

8. Shell Programming and Scripting

SED text edit help needed

Could someone please tell me how to delete all lines above a line which contains a particular string? (possibly using SED command) I know how to do this if the target string appears in only one line of file but when it appears in multiple lines it only deletes from the first line which the string... (3 Replies)
Discussion started by: stevefox
3 Replies

9. Shell Programming and Scripting

Simple SED edit

I have output like the following: B D 20070116095820001 N D S0000579.LOG S0000582.LOG B D 20070116095750001 N D S0000574.LOG S0000576.LOG B D 20070116095734001 N D S0000570.LOG S0000573.LOG B D 20070116095705001 N D S0000569.LOG S0000569.LOG B D ... (5 Replies)
Discussion started by: rdudejr
5 Replies

10. UNIX for Dummies Questions & Answers

edit file using sed (not create another!)

Hi, I generally use Perl for this ex. perl -e 's/pattern/replace/g' -p -i <filename> I did something like this.. find . -type f -exec perl -e 's/pattern/replace/g' -p -i {} \; I want to do this with "sed" but what I get is the output being printed on the screen.. i can do sed... (3 Replies)
Discussion started by: oldtrash
3 Replies
Login or Register to Ask a Question