The UNIX and Linux Forums  

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
finding string at runtime inderpunj Shell Programming and Scripting 1 05-01-2008 04:19 AM
While finding compare the result with given string mr_bold UNIX for Dummies Questions & Answers 4 04-24-2008 10:31 PM
finding a string in a file Ume1986 UNIX for Advanced & Expert Users 2 01-24-2008 07:19 AM
Finding part of a string DAFNIX Shell Programming and Scripting 4 09-21-2006 12:24 AM
Finding a certain string on each line in a file VODAFUN Shell Programming and Scripting 5 10-07-2005 06:48 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 09-16-2007
sandyg sandyg is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 3
Exclamation help with finding a string

Hello folks

I have a text file abcd.txt and has a line starting with number '8'.

I have a string in this line starting at position 'a' to position 'b'
also this string is a number and have to be reduced by 1. there is also a problem that it has to be padded with zeros to make the string always with 6 characters.


eg: abcd.txt

content of this file:

1ahdhliehgoei
5abldflierjlijuero903489 034309842098
8000000020809832021090-34

the third line starting with 8 has to be changed. the string starts at position 4 to position 9.

so 000002 has to be reduced by 1 and shown as 000001

and the output should look like this in the same abcd.txt file.

1ahdhliehgoei
5abldflierjlijuero903489 034309842098
8000000010809832021090-34


how can this be changed in shell scripting

I would appreciate if someone can help me on this.


Thanks in advance....
  #2 (permalink)  
Old 09-16-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,558
try to code up something first nex time

Code:
awk '/^8/{ 
          tochange=substr($0,4,6)
          printf "%s%06s%s\n", substr($0,0,3), tochange-1 ,substr($0,9)          
          }
     !/^8/{print}
' "file"

  #3 (permalink)  
Old 09-28-2007
sandyg sandyg is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 3
Thank You... you're awesome...
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:49 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