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
find and replace using sed arvind_aks15 Shell Programming and Scripting 2 07-18-2008 05:26 PM
Find and Replace NycUnxer UNIX for Dummies Questions & Answers 4 03-06-2008 12:20 AM
find replace dbsurf Shell Programming and Scripting 2 01-25-2008 08:39 AM
find and replace valhutch UNIX for Dummies Questions & Answers 4 07-29-2006 05:20 PM
Find & Replace gagansharma Shell Programming and Scripting 3 11-27-2001 04:17 PM

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

Join Date: Dec 2008
Posts: 38
awk find/replace

Greetings all.

I have web site that has long option and switch lists. When I insert something new into these files, the lists need to be reordered. IE:

1 => apple
2 => pear
3 => bannana
4 => orange
---------------------
Add grape as #2

1 => apple
2 => grape
3 => pear
4 => bannana
5 => orange

In this example it is easy to reorder. However my files have close to 200 entries. Making the reordering very tedious and labor intensive.

What I am wondering, is it possible to use awk find/replace along with C to automate this process?

The idea would be to construct a while loop, find the next number to replace and replace it with the next higher number. Loop through the process until finished.

Does that sound like the easiest solution or is there something easier/better out there?

Thank you for your thoughts.
~Robert
  #2 (permalink)  
Old 03-08-2009
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
Hi,

What scripting language are you using on your web server? php, python, perl ...?

If your pages are static, it won't be that easy. Possible but not easy.
  #3 (permalink)  
Old 03-08-2009
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by RobertSubnet View Post
...
I have web site that has long option and switch lists. When I insert something new into these files, the lists need to be reordered. IE:

1 => apple
2 => pear
3 => bannana
4 => orange
---------------------
Add grape as #2

1 => apple
2 => grape
3 => pear
4 => bannana
5 => orange

In this example it is easy to reorder. However my files have close to 200 entries. Making the reordering very tedious and labor intensive.
...

Assuming the given format, you can work on something along the lines of ...

Code:
nawk  '$1==n { print n " => " s } $1>=n { $1++ } 1' n=2 s="grape" list_file
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 11:31 AM.


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