Sed options


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed options
# 1  
Old 03-18-2009
Sed options

I have a file with name input_file.spec.

This file has records like:


Record #: 1

rec_len = 590
rec_id = 31229
filler_4 = " "
orig_id = 902162988
seqnum = 138960799
lrnid = "0"
l_ind = "0"
transaction_cnt = 1
cust_id = 61032336
product_id = 135488621

ans so on.

It has 1000 records in this file.

I have to give new numbering to seqnum field only.
i am gogin to start with 1 and ll end with 1000.

I worte this:

#!/bin/ksh
i=1
echo "Give input file"
INPUTFILES=input_file.spec
cat $INPUTFILES | while read LINE
do
let i=i+1
sed -e '/seqnum/s/seqnum = [0-9]*/seqnum = '$i'/g' $LINE
done


but the "i" is not getting interpolated event when its reading line by line.

Can u please tell any option in unix to do the same.
or alternative to do the same business.
# 2  
Old 03-18-2009
Try this:

Code:
awk '/seqnum/{$NF=++i}1' file

Regards
# 3  
Old 03-18-2009
Sorry i didnt wrk as per my requirements.
Can u please lookin the sed only?

Thanks and Regards,
# 4  
Old 03-19-2009
in your sed command, try replacing single quotes with double quotes

and you have to take care of escaping (characters such as < " * etc) then
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Sed error - multiple number options to `s' command

Hi All, I am having two files (file1 & file2) and a filelist.txt file below. file1: $$STRINGVAR1=5 $$STRINGVAR2=10 $$LAST_UPD_DT_TBL1=12/12/2010 12:00:00 $$STRINGVAR3=100 $$LAST_UPD_DT_TBL2=01/01/2010 12:00:00... (8 Replies)
Discussion started by: Chandru_Raj
8 Replies

2. Ubuntu

Kernel boot options removed by fault, no boot options

Hello Everyone, First of all, I highly appreciate all Linux forum members and whole Linux community. http://forums.linuxmint.com/images/smilies/icon_wink.gif. I wish you the best for all of you ! I will try to be short and concise: I am using Linux Mint 10 for 2 months on 2 ws, and all went... (3 Replies)
Discussion started by: cdt
3 Replies

3. Shell Programming and Scripting

cut, sed, awk too slow to retrieve line - other options?

Hi, I have a script that, basically, has two input files of this type: file1 key1=value1_1_1 key2=value1_2_1 key4=value1_4_1 ... file2 key2=value2_2_1 key2=value2_2_2 key3=value2_3_1 key4=value2_4_1 ... My files are 10k lines big each (approx). The keys are strings that don't... (7 Replies)
Discussion started by: fzd
7 Replies

4. UNIX for Advanced & Expert Users

Use of SED in Perl or any other options

Hi Folks, I am working on a data extraction script in perl.I am a begineer in perl and shell scripting. So i need your inputs to solve the script problem. I have data coming from database in the format :- <b> _ABC (Apply Changes) (p) </b> _EFG | HIJ | KLM | WER <b> _E3R (Apply Changes)... (3 Replies)
Discussion started by: subhotech
3 Replies

5. AIX

no options

Hi All, I have a situation here that's very fun... I have a system with AIX and iPlanet (sunOne) installed, when occurs an unknown event on the network the WebServer shows a thousand of CLOSE_WAIT connections and this number grows and grows until the webserver crashs. I read some documents... (2 Replies)
Discussion started by: nascimento.rp
2 Replies

6. UNIX for Dummies Questions & Answers

options

I am just beginning to learn unix and I was wondering if there was a list of all the options somewhere on the net or hidden in the man pages? Also do options always have - and then a letter, or can it be - and a number as well? Thanks! (1 Reply)
Discussion started by: terms5
1 Replies

7. Shell Programming and Scripting

sed h and g options

Hi .. Happy New Year.. If i do a sed -e ' /BEGIN/,/END/{ h /xxx/{ g p } } ' temp1 I have two queries in this script 1.Will the block between BEGIN and END be stored in the hold buffer before executing the /xxx/ .. (9 Replies)
Discussion started by: sivasenthil_k
9 Replies

8. UNIX for Dummies Questions & Answers

cp options

Hello again, Is there an option for the cp command to overwrite existing files in the destination directory? Cheers Rob (3 Replies)
Discussion started by: milage
3 Replies
Login or Register to Ask a Question