Sponsored Content
Top Forums Shell Programming and Scripting Read column values from previous and next line using awk Post 302708953 by Nishi_Licious on Tuesday 2nd of October 2012 12:23:23 PM
Old 10-02-2012
What I gave above is the output i want.

The input is like this:
Code:
       Key1              Key2              Key3       102                 30                   0       102   40   1       102   50   2       103   12   0       103   15   1

I need to add three new columns to the existing columns above and insert data into them from the column Key2.

The output is expected to look like this:
Code:
         Key1   Key2   Key3   New_Key1   New_Key2   New_Key3       102   30   0   -   -   -       102   40   1   30   40   50       102   50   2   40   50   30       103   12   0   -   -   -       103   15   1   12   15   12

The first row to any unique Key1, has New_Key1, New_Key2, New_Key3 dashed out. Now for the next row, the first value of Key2(in this case 30) becomes New Key1, the second value of Key2(40) fills in for New_Key2 and the third value(50) fills in for New_Key3. The process then repeats for the next row where the 2nd, 3rd and 4th values of Key2 are taken to fill New_Key1, New_Key2 and New_Key3 repectively. All this happens provided its mapped to the same Key1. I hope I'm clearer now.

Last edited by Corona688; 10-03-2012 at 12:23 PM.. Reason: Missed out some information and the content was not clearly formatted.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to read the column and print the values under that column

hi all:b:, how to read the column and print the values under that column ...?? file1 have something like this cat file1 ======= column1, column2,date,column3,column4..... 1, 23 , 12/02/2008,...... 2, 45, 14/05/2008,..... 3, 56, 16/03/2008,..... cat file2 =======... (6 Replies)
Discussion started by: gemini106
6 Replies

2. Shell Programming and Scripting

read column values one after another

hi, Can some one help me how to retrieve column values row by row My requirement is like below : I have a text file having comma seperated values of these records . OName OType SrcDB Sschema targetdb TSchema Load Dataype processY/N aa Table a e i m Y db2 y aa index b c d e N sql N ... (4 Replies)
Discussion started by: sailaja_80
4 Replies

3. UNIX for Advanced & Expert Users

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

4. UNIX for Dummies Questions & Answers

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

5. Shell Programming and Scripting

eAdd two fields in a column if their previous field values are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output file as follows If field3 in file1 is same as field3 in the next line then the field4 should add... (1 Reply)
Discussion started by: yerruhari
1 Replies

6. Shell Programming and Scripting

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (3 Replies)
Discussion started by: yerruhari
3 Replies

7. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

8. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

9. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

10. Shell Programming and Scripting

Insert data in first column(if blank) from previous line first column

Dear Team I need to insert field(which is need to taken from previous line's first field) in first column if its blank. I had tried using sed but not find the way. Detail input and output file as below. Kindly help for same. INPUT: SCGR SC DEV DEV1 NUMDEV DCP ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies
LE(1)							      General Commands Manual							     LE(1)

NAME
le - full screen text editor SYNOPSIS
le [options] filename DESCRIPTION
le is a text editor which offers wide range of capabilities with a simple interface. It has a pull down menu and a simple help system to get started. See KEYS section below to learn about key combinations. Among its features there are: various operations with stream and rectangular blocks, search and replace with full regular expressions, text formatting, undelete/uninsert, hex editing, tunable key sequences, tunable colors, tunable syntax highlighting. The editor currently supports only one loaded file at a time. KEYS
Here are some starting hints: F10 or C-n menu F1 help C-x exit (cancel) Arrows navigate In the editor the following key description is used: Key1-Key2 simultaneous key1 and key2 press Key1+Key2 sequential keys press Key1 | Key2 press Key1 OR Key2 ^Key Ctrl-Key ~Key Shift-Key ^~Key Ctrl-Shift-Key | Alt-Key Some of ^Fx, ~Fx, ^~Fx can be typed as ESC+Fx. The rest of key combinations can be seen in help, in menu and in the keyboard map (default one can be seen with le --dump-keymap). There is support for block filtering through an external program, a command output read-in, writing a block through a command. To read or write block from/to a command, use F4+R or F4+W and file name of the following format: ``|command args''. Filtering is achieved by F4+| followed by command name. STATUS LINE
On the status line you can see current line, column, the size of loaded file, the code of character under cursor, several one letter flags, file name, offset in bytes from the file beginning and percent position in the file. One letters flags are: * - modified; R - Russian keyboard (works only on certain terminals); I - insert, O - overstrike; A - autoindent; D - dos style line terminators (CR NL); U - undelete possible, u - uninsert possible; B - column block mode. TEXT PROTECTION
To prevent changes loss on crash, le regularly dumps the editing text, if changed, to ~/.le/tmp/FILENAME.PID , where FILENAME is the file name with slashes converted to underlines; PID is the process id of the editor process. When the editor gets a fatal signal, it also dumps the text, to ~/.le/tmp/DUMP-SIG-FILENAME.PID , where SIG is the signal number. OPTIONS
-r, --read-only Work as viewer, don't allow changes. If your system supports mmap(2), it will be used to get file contents to memory. -h, --hex-mode Start in hex mode --mmap Use mmap(2) to load file read-only. Can be used to view very large files or even devices. This implies -h. --mmap-rw Use mmap(2) to load file read-write in MAP_SHARED mode. Use with caution -- the changes go directly to file or disk, no undo. In this mode only replace can be used, but it allows editing of very large files or even devices. This implies -h. -b, --black-white Start in black & white mode -c, --color Start in color mode --dump-keymap Dump default keymap to stdout and exit --dump-colors Dump default color map to stdout and exit --version Print the version of LE and exit --help Print short description of options and exit FILES
DATADIR/colors ~/.le/colors DATADIR/colors-$TERM ~/.le/colors-$TERM Color palette description. Those files are sequentially read and color definitions in later files have higher precision. ~/.le/keymap-$TERM DATADIR/keymap-$TERM ~/.le/keymap DATADIR/keymap Key map descriptions. Only the first existing file is read. ~/.le/term-$TERM DATADIR/term-$TERM Terminal specific options. Only the first existing file is read. Use Options->Terminal menu to tune the options. ./.le.ini ~/.le/le.ini DATADIR/le.ini Options. Only the first existing file is read. Use menu Options to tune these. .le.syntax ~/.le/syntax DATADIR/syntax Syntax highlighting rules. Only the first existing file is read. There is no default built-in in the editor, so if those files are not present you won't see any syntax highlighting. ~/.le/mainmenu DATADIR/mainmenu Main editor menu. It has simple text format. Only the first existing file is read. ~/.le/history Various histories are saved here. Do not edit by hand. DATADIR is determined at compile time by configure script (pkgdatadir variable). By default it has value /usr/local/share/le. AUTHOR
The LE editor was written by Alexander V. Lukyanov <lav@yars.free.net>. 28 Sep 2000 LE(1)
All times are GMT -4. The time now is 02:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy