Need help in building Unix script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in building Unix script
# 8  
Old 03-24-2009
Thank you.

It seems if we will modify something in this code,it will work, I checked and got the following output.

+1 Madhu inside BUILD_BACKGROUND_TABLES
+2 Madhu inside BUILD_BACKGROUND_items
+3 Madhu inside build_background_price_mstr
+4 Madhu inside build_background_price_dtl
+5 Madhu inside wiz_finalize_ndh_copy
+6 Madhu inside For
+7 Madhu before calling part load
+8 Madhu v_item_already_exists N
+9 Madhu Populating prices inside for 1
+10 Madhu before calling price_load.populate_bms_price



Out put

+1 Madhu 123456 BUILD_BACKGROUND_TABLES
+2 Madhu 123456 BUILD_BACKGROUND_items
+3 Madhu 123456 build_background_price_mstr
+4 Madhu 123456 build_background_price_dtl
+5 Madhu 123456 wiz_finalize_ndh_copy
+6 Madhu 123456 For
+7 Madhu before calling part load
+8 Madhu v_item_already_exists N
+9 Madhu Populating prices 123456 for 1
+10 Madhu before calling price_load.populate_bms_price
+11 mADDY IN HERE TAB COUNT =1

But we wanted the following output

+1 Madhu inside BUILD_BACKGROUND_TABLES
+2 Madhu 123456 BUILD_BACKGROUND_items
+3 Madhu inside build_background_price_mstr
+4 Madhu inside build_background_price_dtl
+5 Madhu inside wiz_finalize_ndh_copy
+6 Madhu inside For
+7 Madhu before calling part load
+8 Madhu v_item_already_exists N
+9 Madhu Populating prices inside for 1
+10 Madhu before calling price_load.populate_bms_price

Regards
Susant
# 9  
Old 03-24-2009
hi,

Oops sorry i was in other task..

hope this should work..

Code:
for f in `ls -lrt *.lst |awk '{print $9}'`
do
string=`awk '/+=/ {getline;print $2}' $f`
echo $string
sed -i "s/$string/new1234567/" $f
done

Thanks
SHa
# 10  
Old 03-24-2009
Thank you SHa,
I am not much experienced in either AWK or SED, I am getting the following error

awk: 0602-521 There is a regular expression error.
?*+ not preceded by valid expression.

The source line number is 1.
The error context is
>>> /+=/ <<< {getline;print $2}

sed: Not a recognized flag: i
Usage: sed [-n] Script [File ...]
sed [-n] [-e Script] ... [-f Script_file] ... [File ...]

Regards
Susant
# 11  
Old 03-24-2009
Hi Susant,

Not sure what exactly problem in your end..however that was working for me...well..

Smal changes done ..so hope this should work now..

Code:
for f in `ls -lrt *.lst |awk '{print $9}'`
do
Value=`head -2 $f|tail +2|awk '{print $2}'`
echo $Value
sed "s/$Value/12345/1" $f > out.lst
mv out.lst $f
done

Note here $9 is for 9th Field(Filename) according to ls -lrt command ..make sure in your server..it should 9th field..
ALso no of occurance in sed command should be 1 not a g to avoid all replacement..

Thanks
Sha

Last edited by Shahul; 03-24-2009 at 09:44 AM..
# 12  
Old 03-24-2009
Thank you very much SHa..You are just a Genious.... Smilie

It worked flawlessly Smilie

With tons of thanks Smilie
Susant
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

UNIX: Building The Most Important OS in the World By John Loeffler

Nice UNIX history article by John Loeffler, February, 05th 2019 UNIX: Building The Most Important OS in the World The most widely used operating system in the world was a project born out of failure. (0 Replies)
Discussion started by: Neo
0 Replies

2. Shell Programming and Scripting

Building a dynamic UNIX menu with input files

Hi! I am looking to build dynamic menu (named: lookup.sh) that reads a pipe delimited file for input. for example, contents of input.txt could be: user1|srv1 user3|srv1 user4|srv1 user2|srv2 I want the menu look like: 1) get password for user1 on srv1 2) get password for user3 on... (7 Replies)
Discussion started by: cpolikowsky
7 Replies

3. UNIX for Dummies Questions & Answers

Error building program in UNIX

I'm trying to build a program and I'm getting a series of messages that I don't understand (new to UNIX): make: Entering directory `/disk/cg6/ccoda/code/proj/abrupt/exp/cam1/models/atm/cam/tools/scam/ui' g++ -c -Wall -g -DLINUX -DREAL_TYPE=double -DNeedFuncProto ... (7 Replies)
Discussion started by: bstephens
7 Replies

4. UNIX for Advanced & Expert Users

Building a Unix Server from Scratch?

Hello Everyone, This post is a result of my search and quest to build a Unix Server at Home. I am familiar with the most of the systems such as, Solaris 10, HP-UX & Linux. Can somebody help me with more information about How to Build a Unix Server right from Fundamentals.... ? I have... (5 Replies)
Discussion started by: Vabiosis
5 Replies

5. Shell Programming and Scripting

Need help in building Unix script

Hi all, We have a requirement like we need to create a program which will change a particular string in the file. For example +=KA1238767 1121 3344645 686943 22356 01 567893 12435 12121 983627 121 1092 091217 02 may be for engine failure In the above file we need to change the bold string... (2 Replies)
Discussion started by: susant.igate
2 Replies

6. UNIX for Dummies Questions & Answers

Building from scratch - UNIX

Hi! Any knows if Unix (from IBM, Sun, HP, etc) is picky on hardwares? I mean, installing Unix (not Linux) on a custom build system? Thanks. (2 Replies)
Discussion started by: genesisX
2 Replies

7. Shell Programming and Scripting

Building a Linux like LS for Unix

I'm trying to customize my environment at work in a Unix system. So I'm starting with the ls command... I'd like to make it run as the Linux ls... Even in color, if possible... My first problem is to make the file listing brake in columns... In fact, the actual ls from Unix does this, but... (3 Replies)
Discussion started by: 435 Gavea
3 Replies

8. Shell Programming and Scripting

Help building the logic for a script

Hi guys, I am new to shell scripting, i need your help to tackle a problem. I have a single file, sample is below: 2008:07:08 07:01:14.360 (tid 4) INFO no bonus notifications to send 2008:07:08 07:01:50.823 (tid 1) INFO Database cleaned of all stale bonus records order than 30 days... (3 Replies)
Discussion started by: fahadaizaz
3 Replies

9. Shell Programming and Scripting

building a SET clause in shell script

Hi, I have a comma delimited string, e.g. empno, ename, sal. Using Korn Shell Script I want to build the SET clause for an UPDATE statement, and set clause should look like this: empno=decode(:empno, '?', empno, :empno), ename=decode(:ename, '?', empno, :ename), sal=decode(:sal, '?',... (14 Replies)
Discussion started by: shalua
14 Replies

10. UNIX for Advanced & Expert Users

building flat files in unix and importing them from windows

what is a flat file in unix? i have to import a unix flat files from windows based programme. my question is not to export from unix but only to import from windows only. how to build that flat files? how to create export to windows how to import from windows (3 Replies)
Discussion started by: tunirayavarapu
3 Replies
Login or Register to Ask a Question