The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Translating gcc/g++/gfortran Options to Sun Studio Compiler Options iBot Solaris BigAdmin RSS 0 02-04-2009 02:30 PM
no options nascimento.rp AIX 2 08-20-2006 02:46 PM
options terms5 UNIX for Dummies Questions & Answers 1 01-27-2006 01:50 AM
options with awk mips Shell Programming and Scripting 2 05-15-2004 03:33 AM
cp options milage UNIX for Dummies Questions & Answers 3 07-13-2001 12:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2009
Ajay_84 Ajay_84 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
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 (permalink)  
Old 03-18-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,307
Try this:

Code:
awk '/seqnum/{$NF=++i}1' file
Regards
  #3 (permalink)  
Old 03-18-2009
Ajay_84 Ajay_84 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
Sorry i didnt wrk as per my requirements.
Can u please lookin the sed only?

Thanks and Regards,
  #4 (permalink)  
Old 03-19-2009
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
in your sed command, try replacing single quotes with double quotes

and you have to take care of escaping (characters such as < " * etc) then
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0