Flat file manipulation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Flat file manipulation
# 1  
Old 05-27-2009
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  
Old 05-27-2009
try:
Code:
sed '4,4 {
s/102346/102347/
}' file

# 3  
Old 05-27-2009
Quote:
Originally Posted by mohan705
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  
Old 05-28-2009
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  
Old 05-28-2009

You haven't explained the process by which this:

Quote:
Originally Posted by mohan705
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  
Old 05-28-2009
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  
Old 05-28-2009
Quote:
Originally Posted by mohan705
sorry for not explained properly,I want to increment 1st column

I repeat: Which lines do you want incremented?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed flat file manipulation

Hello, I have a large flat file where i need to change data in columns 131-133 based on what is in columns 172-173. I am not sure if I need to read the file line by line and make the change or if I can do this in a single statement. thank you (3 Replies)
Discussion started by: gblmin
3 Replies

2. Shell Programming and Scripting

reading a csv file and creating a flat file

hi i have written a script for reading a csv file and creating a flat file, suggest if this script can be optimized #---------------- FILENAME="$1" SCRIPT=$(basename $0) #-----------------------------------------// function usage { echo "\nUSAGE: $THIS_SCRIPT file_to_process\n"... (3 Replies)
Discussion started by: mprakasheee
3 Replies

3. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

4. Shell Programming and Scripting

Flat File column manipulation

Hi All, I have a tab delimited input file with say 4 fields (columns) as below : 0000443 1AGPR061 2006 Daiml 0002198 1B3XG0K2 1989 Chdds 0002199 1Bd64J0L 1990 Ch34s 0002275 1B3s4J0K 1989 Chadys 0002276 1B465302 2002 Dageml 0002290 1B45430K 1989 Cays I want the 2nd column in file to... (5 Replies)
Discussion started by: net
5 Replies

5. Programming

compare XML/flat file with UNIX file system structure

Before i start doing something, I wanted to know whether the approach to compare XML file with UNIX file system structure. I have a pre-configured file(contains a list of paths to executables) and i need to check against the UNIX directory structure. what are the various approches should i use ? I... (6 Replies)
Discussion started by: shafi2all
6 Replies

6. Shell Programming and Scripting

Flat File in HP-UX

Hi I have a file like below . IF the record starts with ASD then change the 20th offset to "K" follwed by that 20th offset value & if the record starts with ASDR then change the 38th offset to "K" followed by 38th offset value . But here the condition is the next value ... (0 Replies)
Discussion started by: Krishnaramjis
0 Replies

7. Shell Programming and Scripting

Flat file

Hi I have a flat file looking this QWER 2:35 7044 00001 ROUT 1188 EA SS ASD 2:36 7044 00010 ROUT BSD 2:37 7044 00011 ROUT END QWER 3:35 7044 00011 ROUT 1088 EA SS ASD 3:36 7044 00010 ROUT BSD 3:37 7044 00011 ROUT... (9 Replies)
Discussion started by: Krishnaramjis
9 Replies

8. Shell Programming and Scripting

Flat file manipulation, (this could be a tough one)

Howdy everyone, I have need of a scripting brain to help me through the following issue: *This will help if I explain what I am doing this for and then it may make sense. I need to change a flat file to prepend a 3 digit code to a certain field in the file going on the value in another scetion of... (2 Replies)
Discussion started by: mrbungle50
2 Replies

9. Shell Programming and Scripting

Help with a Flat File!!!

Hi All, I need a help with a shelll script program.I get a '|' separated file which sometime has a encrypted column.And this encryption sometime breaks the last column data into a new line and this is not picked by the ETL.So when i run a script,it should append back the broken new line data... (11 Replies)
Discussion started by: kumarsaravana_s
11 Replies

10. Shell Programming and Scripting

Help with a flat file!!!

Hi All, I get a flat file everyday with some records being invalid.Some records come with less number '|'.I just want to add the missing '|'s ,So the it doesnt give an error insufficient fields while loading...There area total of 32 pipes in each record. Input: ASADASD |Y|B|SDFGDSDFD| ... (3 Replies)
Discussion started by: kumarsaravana_s
3 Replies
Login or Register to Ask a Question