Sponsored Content
Top Forums Shell Programming and Scripting awk script to insert text in file Post 302294930 by pk218703 on Friday 6th of March 2009 07:06:40 AM
Old 03-06-2009
awk script to insert text in file

I'm in a time crunch here and I don't know how to write scripts.

I have a file of data that looks like the following:

1 7.652073E+00 0.000000E+00 7.146691E+02 1.704154E+01
2 7.652068E+00 6.031387E+00 7.146636E+02 2.499305E+01
3 7.645906E+00 1.509455E+01 7.144158E+02 1.822061E+02
4 7.644384E+00 0.000000E+00 7.060164E+02 1.906207E+02
5 7.644851E+00 1.656708E+01 7.143705E+02 2.082920E+02
6 7.643266E+00 0.000000E+00 7.049532E+02 2.136475E+02
7 7.652025E+00 5.653657E+00 7.146640E+02 2.484270E+01
8 7.652030E+00 0.000000E+00 7.146688E+02 1.696780E+01
9 7.648590E+00 1.493431E+01 7.144656E+02 1.755838E+02
10 7.651975E+00 7.533265E+00 7.146561E+02 3.659776E+01
11 7.652441E+00 0.000000E+00 7.146912E+02 5.900617E+00
12 7.652447E+00 3.129451E+00 7.146904E+02 4.833028E+00
13 7.652094E+00 5.238432E+00 7.146674E+02 2.240046E+01
14 7.652090E+00 0.000000E+00 7.146713E+02 1.565879E+01
15 7.642858E+00 1.637091E+01 7.144912E+02 2.286945E+02

its over 500k lines... i need it to look like this:

1 7.652073E+00 0.000000E+00 7.146691E+02 1.704154E+01 0.100000E+03
0.999900E+04 0.254000E-03
2 7.652068E+00 6.031387E+00 7.146636E+02 2.499305E+01 0.100000E+03
0.999900E+04 0.254000E-03
3 7.645906E+00 1.509455E+01 7.144158E+02 1.822061E+02 0.100000E+03
0.999900E+04 0.254000E-03
4 7.644384E+00 0.000000E+00 7.060164E+02 1.906207E+02 0.100000E+03
0.999900E+04 0.254000E-03
5 7.644851E+00 1.656708E+01 7.143705E+02 2.082920E+02 0.100000E+03
0.999900E+04 0.254000E-03
6 7.643266E+00 0.000000E+00 7.049532E+02 2.136475E+02 0.100000E+03
0.999900E+04 0.254000E-03
7 7.652025E+00 5.653657E+00 7.146640E+02 2.484270E+01 0.100000E+03
0.999900E+04 0.254000E-03
8 7.652030E+00 0.000000E+00 7.146688E+02 1.696780E+01 0.100000E+03
0.999900E+04 0.254000E-03
9 7.648590E+00 1.493431E+01 7.144656E+02 1.755838E+02 0.100000E+03
0.999900E+04 0.254000E-03
10 7.651975E+00 7.533265E+00 7.146561E+02 3.659776E+01 0.100000E+03
0.999900E+04 0.254000E-03
11 7.652441E+00 0.000000E+00 7.146912E+02 5.900617E+00 0.100000E+03
0.999900E+04 0.254000E-03
12 7.652447E+00 3.129451E+00 7.146904E+02 4.833028E+00 0.100000E+03
0.999900E+04 0.254000E-03
13 7.652094E+00 5.238432E+00 7.146674E+02 2.240046E+01 0.100000E+03
0.999900E+04 0.254000E-03
14 7.652090E+00 0.000000E+00 7.146713E+02 1.565879E+01 0.100000E+03
0.999900E+04 0.254000E-03
15 7.642858E+00 1.637091E+01 7.144912E+02 2.286945E+02 0.100000E+03
0.999900E+04 0.254000E-03


is there anyway someone can write me an awk script to insert the 0.100000E+03
0.999900E+04 0.254000E-03

it would be great. it needs to be in that format.

Thanks,
pk
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

2. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

3. Shell Programming and Scripting

Insert Text On file

Hi All, Can someone pls help me to insert some text on a file. my file contains something like below.. AKBULBU, BALUMIL, BATCH,BATCH BOARROB, BOTAKAT, C57896, CAKIOZE, CHECMER, CICOFRA, CISZPAW,2194485 I want output as USER_ID, LOGIN_ID (6 Replies)
Discussion started by: harshakusam
6 Replies

4. Shell Programming and Scripting

Script to insert text from one file to other file

Hello Team, I need help in preparing script which will insert text from one file to other file. I have requirement to prepare script which will insert data from one file to another file. I have tried using sed and awk command but it is not useful to me as it does not append data in the... (12 Replies)
Discussion started by: coolguyamy
12 Replies

5. Shell Programming and Scripting

Insert value to db from text file

Hi, I have a single value in insertval file. I want to load that value to database with the current date. I tried the below code but it is inserting <NULL> to database and echo $c is also null. cat insertval | awk -F ' ' '{print $1}' > c echo c=$c data=`sqlplus -s user/pwd@hostname <<EOF ... (5 Replies)
Discussion started by: Neethu
5 Replies

6. Shell Programming and Scripting

Shell Script to insert text after Tag

Hello, I'm doing an Shell Script to insert a text on XML file, i tried sed, awk, perl... i'm doing something wrong, please help me :) well, the script is a bit large, i get some infos on script before 'run' this part to insert the text on XML... domobile() { let i++ echo ... (1 Reply)
Discussion started by: tassomanoel
1 Replies

7. UNIX for Dummies Questions & Answers

Insert text into a file using shell script

Hi, I need to insert "Hello World" text into a file called hai.txt using shell scripting. Kindly help me. For eg: If I open the file hai.txt by giving linux command cat hai.txt, the content of the file should have the text Hello World in it. Thanks (5 Replies)
Discussion started by: karthick nath
5 Replies

8. Shell Programming and Scripting

How to insert text within a file?

Hi, I am trying to check for missing dates in a file and would want to insert the missing date into the file. Currently the script is as below #!/bin/ksh dates="dates" cat ${dates} | grep -v "^#" curr_month=`date '+%m` curr_day=`date '+%d` curr_year=`date '+%Y` #curr_month=02... (7 Replies)
Discussion started by: newbie_01
7 Replies

9. UNIX for Beginners Questions & Answers

TCL script to insert some text on a file

Hi All , I am looking to create one TCL script to insert one text based on some regular expression match on one file as stated below Input File module (mem1 ,mem2 , bist1 , ten2 , sen1 , land2 , taane2 , ran1 , ran2 , tri2 , tri8 , fly1 , fly2 , san2 ); output ran1 , ran2 , tri2 ,... (1 Reply)
Discussion started by: kshitij
1 Replies
adjust(1)						      General Commands Manual							 adjust(1)

NAME
adjust - simple text formatter SYNOPSIS
column] tabsize] [files]... DESCRIPTION
The command is a simple text formatter for filling, centering, left and right justifying, or only right justifying text paragraphs, and is designed for interactive use. It reads the concatenation of input files (or standard input if none are given) and produces on standard output a formatted version of its input, with each paragraph formatted separately. If is given as an input filename, reads standard input at that point (use as an argument to separate from options.) reads text from input lines as a series of words separated by space characters, tabs, or newlines. Text lines are grouped into paragraphs separated by blank lines. By default, text is copied directly to the output, subject only to simple filling (see below) with a right mar- gin of 72, and leading spaces are converted to tabs where possible. Options The command recognizes the following command-line options: Do not convert leading space characters to tabs on output; (output contains no tabs, even if there were tabs in input). Center text on each line. Lines are pre- and post-processed, but no filling is performed. Justify text. After filling, insert spaces in each line as needed to right justify it (except in the last line of each paragraph) while keeping the justified left margin. After filling text, adjust the indentation of each line for a smooth right margin (ragged left margin). Set the right fill margin to the given column number, instead of 72. Text is filled, and optionally right justified, so that no output line extends beyond this column (if possible). If is given, the current right margin of the first line of each paragraph is used for that and all subsequent lines in the para- graph. By default, text is centered on column 40. With the option sets the middle column of the centering "window", but auto- sets the right side as before (which then determines the center of the "window"). Set the tab size to other than the default (eight columns). Only one of the and options is allowed in a single command line. Details Before doing anything else to a line of input text, first handles backspaces, rubbing out preceding characters in the usual way. Next, it ignores all nonprintable characters except tab. It then expands all tabs to spaces. For simple text filling, the first word of the first line of each paragraph is indented the same amount as in the input line. Each word is then carried to the output followed by one space. "Words" ending in terminal_character[quote][closing_character] are followed by two spa- ces, where terminal_character is any of or quote is a single closing quote or double-quote character (), and close is any of or Here are some examples: does not place two spaces after a pair of single closing quotes following a terminal_character). starts a new output line whenever adding a word (other than the first one) to the current line would exceed the right margin. understands indented first lines of paragraphs (such as this one) when filling. The second and subsequent lines of each paragraph are indented the same amount as the second line of the input paragraph if there is a second line, else the same as the first line. also has a rudimentary understanding of tagged paragraphs (such as this one) when filling. If the second line of a paragraph is indented more than the first, and the first line has a word beginning at the same indentation as the second line, the input column position of the tag word or words (prior to the one matching the second line indentation) is preserved. Tag words are passed through without change of column position, even if they extend beyond the right margin. The rest of the line is filled or right justified from the position of the first nontag word. When is given, uses an intelligent algorithm to insert spaces in output lines where they are most needed, until the lines extend to the right margin. First, all one space word separators are examined. One space is added to each separator, starting with the one having the most letters between it and the preceding and following separators, until the modified line reaches the right margin. If all one space separators are increased to two spaces and more spaces must be inserted, the algorithm is repeated with two space separators, and so on. Output line indentation is held to one less than the right margin. If a single word is larger than the line size (right margin minus indentation), that word appears on a line by itself, properly indented, and extends beyond the right margin. However, if is used, such words are still right justified, if possible. If the current locale defines class names and (see iswctype(3C)), formats the text in accordance with the character classification and mar- gin settings (see and options). EXTERNAL INFLUENCES
Environment Variables provides a default value for the internationalization variables that are unset or null. If is unset or null, the default value of "C" (see lang(5)) is used. If any of the internationalization variables contains an invalid setting, will behave as if all internationalization variables are set to "C". See environ(5). If set to a nonempty string value, overrides the values of all the other internationalization variables. determines the interpretation of text as single and/or multi-byte characters, the classification of characters as printable, and the char- acters matched by character class expressions in regular expressions. determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informa- tive messages written to standard output. determines the location of message catalogs for the processing of International Code Set Support Single- and multi-byte character code sets are supported. DIAGNOSTICS
complains to standard error and later returns a nonzero value if any input file cannot be opened (it skips the file). It does the same (but quits immediately) if the argument to or is out of range, or if the program is improperly invoked. Input lines longer than are silently split (before tab expansion) or truncated (afterwards). Lines that are too wide to center begin in column 1 (no leading spaces). EXAMPLES
This command is useful for filtering text while in vi(1). For example, reformats the rest of the current paragraph (from the current line down), evening the lines. The command: (where denotes control characters) sets up a useful "finger macro". Typing (Ctrl-X) reformats the entire current paragraph. is a simple way to break text into separate words without whitespace, except for tagged-paragraph tags. WARNINGS
This program is designed to be simple and fast. It does not recognize backslash to escape whitespace or other characters. It does not recognize tagged paragraphs where the tag is on a line by itself. It knows that lines end in newline or null, and how to deal with tabs and backspaces, but it does not do anything special with other characters such as form feed (they are simply ignored). For complex opera- tions, standard text processors are likely to be more appropriate. This program could be implemented instead as a set of independent programs, fill, center, and justify (with the option). However, this would be much less efficient in actual use, especially given the program's special knowledge of tagged paragraphs and last lines of para- graphs. AUTHOR
was developed by HP. SEE ALSO
nroff(1). adjust(1)
All times are GMT -4. The time now is 04:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy