Flat file manipulation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Flat file manipulation
# 8  
Old 05-28-2009
Code:
for example
I have 2 lines in flat file ,I want to add another 100 lines with different account numberS.

accno    am1   amt2 amt3
102345  1000  200     300

102346  1000   200      300

o/p

accno    am1   amt2    amt3
102345  1000  200     300
102346  1000   200     300
102347  1000   200     300
102348  1000   200     300
..
..
102445  1000   200     300

Thanks,
MR
# 9  
Old 05-28-2009
Quote:
Originally Posted by mohan705
Code:
for example
I have 2 lines in flat file ,I want to add another 100 lines with different account numberS.
 
accno    am1   amt2 amt3
102345  1000  200     300
102346  1000   200      300
 
o/p
 
accno    am1   amt2    amt3
102345  1000  200     300
102346  1000   200     300
102347  1000   200     300
102348  1000   200     300
..
..
102445  1000   200     300

...
Although you mention "another 100 lines", your output shows that you added another 99 lines.

Here's one way to do it:

Code:
$
$ cat input.txt
102345  1000  200     300
102346  1000  200     300
$
$
$ perl -ne 'print; $x= substr($_,0,index($_," ")); $y = substr($_,index($_," "));
>           END {foreach $i(1..99) {print $x+$i,$y}}' input.txt
102345  1000  200     300
102346  1000  200     300
102347  1000  200     300
...
... <snipped output for brevity>
102443  1000  200     300
102444  1000  200     300
102445  1000  200     300
$
$

tyler_durden
# 10  
Old 05-28-2009

Code:
awk '{print}END{n=0;while ( n++ < 100 ) { $1++ ; print }}'

# 11  
Old 05-29-2009
Hi
Thanks guys its working fine.Using perl I want increment 3 rd column values also.

Code:
$ cat input.txt
102345  1000  200     300
102346  1000  201     300

o/p
102345  1000  200     300
102346  1000  201     300
102347  1000  202     300
102348  1000  203     300
102349  1000  204     300
..............................

Thanks in advance
MR
# 12  
Old 06-06-2009
Hi
When executing the below one it was incrementing precision value ,I want to increment scale value

Code:
perl -ne 'print; $x= substr($_,0,index($_," ")); $y = substr($_,index($_," "));
>           END {foreach $i(1..10) {print $x+$i,$y}}' input.txt



1.10000000,306829
2.1
3.1
4.1
5.1
6.1
7.1
8.1
9.1
10.1

Expecting o/p

1.10000000,306829
1.10000001,306829
1.10000002,306829
1.10000003,306829
1.10000004,306829
......

Thanks in advance
MR
# 13  
Old 06-06-2009
Quote:
Originally Posted by mohan705
...
When executing the below one it was incrementing precision value ,I want to increment scale value
...
Code:
$
$ perl -ne 'print; @x = split/,/; END {foreach $i(1..5) {print $x[0]+$i/100000000,",",$x[1]}}' input.txt
1.10000000,306829
1.10000001,306829
1.10000002,306829
1.10000003,306829
1.10000004,306829
1.10000005,306829
$

tyler_durden
# 14  
Old 06-06-2009
Hi tyler_durden ,

Thanks for your reply


Thanks,
MR
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