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
Flat File column manipulation net Shell Programming and Scripting 5 03-05-2009 03:14 AM
compare XML/flat file with UNIX file system structure shafi2all High Level Programming 6 08-15-2008 03:15 AM
Flat file manipulation, (this could be a tough one) mrbungle50 Shell Programming and Scripting 2 01-10-2008 04:46 AM
Help with a flat file!!! kumarsaravana_s Shell Programming and Scripting 3 04-16-2007 08:58 AM
XML to flat file balireddy_77 Shell Programming and Scripting 2 04-13-2007 06:57 AM

Reply
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 05-27-2009
mohan705 mohan705 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Flat file manipulation

Hi
I have flat file with 100 records ,I need to fabricate data into flat file .

ex:

Code:
file.txt

102345  1000 200  300
...............................
..............................
102346  2000 300  4000


In above file the 4th row, 1 st column valu to be increment by 1 
and rest of the values are same for 1000 lines. 

102347  2000 300  4000

102348  2000 300  4000

Thanks in advance
MR

Last edited by vbe; 05-27-2009 at 12:04 PM..
  #2 (permalink)  
Old 05-27-2009
edgarvm edgarvm is offline
Registered User
  
 

Join Date: May 2009
Posts: 26
try:

Code:
sed '4,4 {
s/102346/102347/
}' file

  #3 (permalink)  
Old 05-27-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365
Quote:
Originally Posted by mohan705 View Post
Hi
I have flat file with 100 records ,I need to fabricate data into flat file .

ex:

Code:
file.txt

102345  1000 200  300
...............................
..............................
102346  2000 300  4000


In above file the 4th row, 1 st column valu to be increment by 1 
and rest of the values are same for 1000 lines. 

102347  2000 300  4000

102348  2000 300  4000


Code:
awk 'NR == 4 { $1 = $1 + 1 } { print }' file.txt

If you want more lines than the 4th incremented, change NR == 4. For example, to get the 4th to the end of the file, change it to NR >= 4.
  #4 (permalink)  
Old 05-28-2009
mohan705 mohan705 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Hi

I tried that only giving 4 recordss,I want first column to be incremente by 1 .

Code:
file.txt

102345  1000 200  300
...............................
..............................
102346  2000 300  4000


I am expecting o/p like this

file.txt

102345  1000 200  300

102346  200 300 400

102347  200 300 400

102348  200 300 400

102349  200 300 400
.............................
..............................
102400  200 300 400

Thank in advance
MR
  #5 (permalink)  
Old 05-28-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365

You haven't explained the process by which this:

Quote:
Originally Posted by mohan705 View Post

Code:
102345  1000 200  300
...............................
..............................
102346  2000 300  4000
is turned into this:

Quote:

Code:
102345  1000 200  300

102346  200 300 400

102347  200 300 400

102348  200 300 400

102349  200 300 400
.............................
..............................
102400  200 300 400
Which lines do you want incremented?

Do you want more than one line of output for any line of input?
  #6 (permalink)  
Old 05-28-2009
mohan705 mohan705 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
sorry for not explained properly,I want to increment 1st column
(102345) and rest of the columns are same


Code:
102345  1000 200  300

102346  200 300 400

102347  200 300 400

102348  200 300 400

102349  200 300 400
.............................
..............................
102400  200 300 400

Thanks in advance
MR
  #7 (permalink)  
Old 05-28-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365
Quote:
Originally Posted by mohan705 View Post
sorry for not explained properly,I want to increment 1st column

I repeat: Which lines do you want incremented?
Reply

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:26 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