File Manipulation - UNIX script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Manipulation - UNIX script
# 1  
Old 10-14-2013
File Manipulation - UNIX script

Hi,
I have a file about 100 lines. Each line is about 2000 characters (each line is fixed length). In middle of each line is following constant value

Code:
0000040029892586

Now, I want to go through each line and increment by 1.
So, line 1 will have 586
line 2 will have 587, line 3 will have 588, so on and so forth.

Thanks,
JaK
# 2  
Old 10-15-2013
Below code might help you.
Code:
awk -F 892  ' (++i) {print i + substr ($2,1,3)  }'  <filename>


Last edited by Franklin52; 10-15-2013 at 02:58 AM.. Reason: Please use code tags
# 3  
Old 10-15-2013
This changes then number in line
Code:
awk '{sub(/40029892586/,i+40029892586);i++} 1' file

# 4  
Old 10-15-2013
Thanks for the prompt help!
# 5  
Old 10-15-2013
If you say that pattern is definitely found in every line, try
Code:
awk 'sub(/40029892586/,NR+40029892585)' CONVFMT="%.f" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Stream manipulation in UNIX shell scripting

i have a file something like this : start: 01:00:00 01:30:00 02:30:00 05:30:00 end: 01:13:00 02:00:00 02:40:00 05:45:00 and i want (end - start) total run time in below format: run: 00:13:00 00:30:00 00:10:00 00:15:00 (4 Replies)
Discussion started by: Acme
4 Replies

2. Shell Programming and Scripting

Manipulation of file data with UNIX

Hello , How all doing today.. I have a little doubt in Unix (6 Replies)
Discussion started by: adisky123
6 Replies

3. UNIX for Dummies Questions & Answers

Help with file manipulation script

I am a UNIX newbee . I have been doing some reading lately but really need help with an an urgent requirement.After almost two days of googling I end up with 0 luck. Hopefully a guru on here will be able to help me out. Here is my requirement: I have 20 files in a directory with detail records... (6 Replies)
Discussion started by: jeyd
6 Replies

4. AIX

Unix File name manipulation

I need a script that will raname the following file names that beging with 08078* in unix as follows: Rename 08078-08201103-H00044-CA.835 as follows: 08078-110820-H000440CA.835 Bascially it will do this: 1) Keep the first 6 positons. 2) Move the yr from the file name to be the... (4 Replies)
Discussion started by: mrn6430
4 Replies

5. Shell Programming and Scripting

Difficult problem: Complex text file manipulation in bash script.

I don't know if this is a big issue or not, but I'm having difficulties. I apoligize for the upcoming essay :o. I'm writing a script, similar to a paint program that edits images, but in the form of ANSI block characters. The program so far is working. I managed to save the image into a file,... (14 Replies)
Discussion started by: tinman47
14 Replies

6. Shell Programming and Scripting

Shell script text file manipulation.

Hello, I have mysql binary file which logs all the database queries and i to insert all queries log in to database. First i coverted binary file to text file. and start playing with it. Text file contains following queries, some samples are, SET INSERT_ID=1; INSERT INTO test... (0 Replies)
Discussion started by: mirfan
0 Replies

7. UNIX for Dummies Questions & Answers

UNIX - File/Table/Data manipulation

Hi, I have a table (e.g.): a 1 e 4 5 6 b 2 r 4 4 2 c 5 r 3 7 1 d 9 t 4 4 9 . . What I need to do is to set the values of some values in column 2 to negative values. For example, the values 2 and 9 should become -2 and -9 in the modified file. How should I go about... (2 Replies)
Discussion started by: pc2001
2 Replies

8. Shell Programming and Scripting

perl script file manipulation

Please let me know.. How to manipulate the data from two files..? I have two files, file1 has two columns one is variable and second is description. file2 has five columns first column is variable and last one is description..Appreciate the help I need to overwrite the description from file1... (5 Replies)
Discussion started by: ddk2oo5
5 Replies

9. Linux

string manipulation in unix

Hi, I have a question . I have script which gets info from db2 engine. The script is cat sample_substitute.sh CNTR_NM=`db2 -x "select CONTAINER_NAME ,usable_pages from table( SNAPSHOT_CONTAINER('TST103',-1)) as SNAPSHOT_CONTAINER, syscat.tablespaces where tablespace_name = tbspace and... (3 Replies)
Discussion started by: capri_drm
3 Replies

10. Shell Programming and Scripting

Unix Shell Novice - File Manipulation

Hi, I am brand new to unix and am hoping someone can start me in the right direction. I want to be able to put the results of a file command such as wc -l filename into a variable which I can then use to test against another variable...i.e. I need to show the nth line of a file, but need to... (3 Replies)
Discussion started by: nmullane
3 Replies
Login or Register to Ask a Question