Script to make simple recurring ascii file edit


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to make simple recurring ascii file edit
# 1  
Old 08-22-2011
Script to make simple recurring ascii file edit

Hi,

I have an ascii file with recurring lines (the file is 36mb so lots of lines) which look like this:

-2.5 -66.324-68.138 935.2 1.953 -0.664 272.617 73.684 -2.428 269.998 0.000

Every 14 lines there is a blank line.

I would like to, for each non-blank line, introduce a space at the 15th character space in the line (i.e. in the above between the '4' and the '-' so I separate the two numbers to give -66.324 -68.138 rather than -66.324-68.138). I want this applying to the first 13 lines, but not the 14th, the next 13 lines but not the 25th, and so on.

Is a short shell script best to sort this? Any help is much appreciated.

Thanks Andy
# 2  
Old 08-22-2011
Looks like character #12 to me, but:

Code:
awk -v FS="" -v OFS="" '{ if(length($1)) $12=$12 " " } 1' < infile > outfile

FS="" tells awk to split each character, whitespace included, into its own record. OFS="" tells awk not to cram spaces between records when printing.

The $12=$12 " " crams on a space after character number 12.

The if-statement makes it not do anything to blank lines.
# 3  
Old 08-22-2011
That works great, thanks very much.

Andy

p.s. it was 14 because there were 2 blank spaces at the beginning of the line which hasnt shown upon posting the thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Hex to Ascii in a Ascii file

Hi All, I have an ascii file in which few columns are having hex values which i need to convert into ascii. Kindly suggest me what command can be used in unix shell scripting? Thanks in Advance (2 Replies)
Discussion started by: HemaV
2 Replies

2. UNIX for Dummies Questions & Answers

How to make user groups and edit permissions?

OK guys and gals. I've been working on a debian system for a little bit, in hopes of making it into a system we can use for manifests and other things. I am very new to unix, particularly debian. I would like to make 2 or 3 different groups. 1 would be for me, and other people... (1 Reply)
Discussion started by: samee71
1 Replies

3. Shell Programming and Scripting

How can I make my script simple?

Hi .. I am trying to print first row few columns and last row few column... I am doing like this... I want to do using single awk for file in *.xyz; do dt_end=$(awk 'END{print $2 "\t" $3 "\t" $4}' FS="," $file) dt_start=$(awk 'FNR == 1{print $1 " \t"$2 }' FS="," $file ) echo $dt_start... (6 Replies)
Discussion started by: nex_asp
6 Replies

4. Shell Programming and Scripting

Help to make the script simple

Hi All, I have a script which throws the output if condition matches. I run the cmd : # ldf Filesystem kbytes used avail capacity Mounted on /dev/dsk/c1t0d0s0 1984564 1375019 550009 72% / /dev/dsk/c1t0d0s3 5040814 2628410 2361996 53% /usr... (4 Replies)
Discussion started by: naw_deepak
4 Replies

5. Shell Programming and Scripting

Help edit simple payroll script?

I'm trying to write a simple script to figure pay with overtime...I got the first part to work, but I can't seem to get the second if statement's syntax right...:confused:I want it to take the 40 hours times 10 dollars, but then i want whatever is left over (like 7 of 47 hours) and take that times... (6 Replies)
Discussion started by: miss72006
6 Replies

6. UNIX for Dummies Questions & Answers

Simple make file questions....i think, thnx

Hello, I'm a noob when comes to make files.... My intentions for the use of my make file are not that of a usual compilation, etc. It is simply to copy some files from a RCS controlled area to a public area which has read rights only for a web page. My dilemma comes in the form of sub... (0 Replies)
Discussion started by: Roxydogg28
0 Replies

7. Programming

c language + simple question regarding memory addresses and ASCII characters

Just a simple question (which may seem silly so bear with me) that arose in my mind the other day. Do ASCII characters by themselves (e.g. /n, 0, a) have an actual memory address ? My question arises, because Im aware that each time I create and initalise a pointer like this for example int... (7 Replies)
Discussion started by: JamesGoh
7 Replies

8. Shell Programming and Scripting

recurring run of sh script in crontab

Hello gurus. I have a problem: my crontab -e is looks like this: ORACLE_SID=bla-bla * 21 * * * (sqlplus hotback/hotback @/oracle/backups/bla-bla/scripts/hotback/daily_hotback.sql) 0 19 * * * /oracle/backups/dev10g/scripts/exports/daily_exports.sh 0 1 * * *... (4 Replies)
Discussion started by: MarGur
4 Replies

9. Shell Programming and Scripting

Simple SED edit

I have output like the following: B D 20070116095820001 N D S0000579.LOG S0000582.LOG B D 20070116095750001 N D S0000574.LOG S0000576.LOG B D 20070116095734001 N D S0000570.LOG S0000573.LOG B D 20070116095705001 N D S0000569.LOG S0000569.LOG B D ... (5 Replies)
Discussion started by: rdudejr
5 Replies

10. UNIX for Dummies Questions & Answers

simple file edit

What command can I use to simply edit a file by searching for a word and then deleting the lines that I find that word in? (4 Replies)
Discussion started by: capesong
4 Replies
Login or Register to Ask a Question