Sponsored Content
Top Forums Shell Programming and Scripting Fill data in column with previous value Post 302935315 by mjf on Saturday 14th of February 2015 07:52:15 PM
Old 02-14-2015
Here is an awk solution:

Code:
$ awk '{if (substr($0,4,4)=="    ") {print substr($0,1,2),save,substr($0,9);} else {save=substr($0,4,4); print $0}}' file.txt
X  4959     30010  66727.00  20457.001    1  1441  66512.00  20234.00  20520.001
X  4959     30010  66727.00  20457.001  145  2961  66524.00  20234.00  20536.001
X  4959     30010  66727.00  20457.001  297  4461  66536.00  20234.00  20532.001
X  4959     30010  66727.00  20457.001  447  6021  66548.00  20234.00  20544.001
X  4959     30010  66727.00  20457.001  603  7621  66560.00  20234.00  20552.001
X  4959     30010  66727.00  20457.001  763  9261  66572.00  20234.00  20560.001
X  4959     30010  66727.00  20457.001  927 10911  66584.00  20234.00  20562.001
X  4959     30010  66727.00  20457.001 1092 12591  66596.00  20234.00  20568.001
X  4959     30010  66727.00  20457.001 1260 14271  66608.00  20234.00  20568.001
X  4959     30010  66727.00  20457.001 1428 15971  66620.00  20234.00  20572.001
X  4960     30010  66727.00  20457.001 1598 17561  66632.00  20234.00  20550.001
X  4960     30010  66727.00  20457.001 1757 19311  66644.00  20234.00  20582.001
X  4960     30010  66727.00  20457.001 1932 21071  66656.00  20234.00  20584.001
X  4960     30010  66727.00  20457.001 2108 22861  66668.00  20234.00  20590.001
X  4960     30010  66727.00  20457.001 2287 24661  66680.00  20234.00  20592.001
X  4960     30010  66727.00  20457.001 2467 26421  66692.00  20234.00  20584.001
X  4970     30010  66727.00  20457.001 2643 28161  66704.00  20234.00  20580.001
X  4970     30010  66727.00  20457.001 2817 30001  66716.00  20234.00  20600.001
X  4970     30110  66511.00  20273.001    1  2241  66512.00  20050.00  20496.001
X  4970     30110  66511.00  20273.001  225  4481  66524.00  20050.00  20496.001
X  4970     30110  66511.00  20273.001  449  6721  66536.00  20050.00  20496.001
X  4970     30110  66511.00  20273.001  673  8961  66548.00  20050.00  20496.001

Code:
awk '{if($2 == ""){$2=A}} {A=$2} 1' Input_file

RavinderSingh13's awk solution above does not appear to work as is since $2 will be valued from a different column (e.g 30010)when the expected field is missing (as file is column delimited).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to fill the name of the spread sheet as a cell's data

In open office spreadsheet, i would like to fill a cell with the name of the spread sheet. That is if the file name of spread sheet is, team.ods, then i have to fill a specific cell with that name 'team'. How to do that ? I have more spread sheets to be created, so i want it to be done... (0 Replies)
Discussion started by: thegeek
0 Replies

2. Shell Programming and Scripting

How to fill data from other file and get some output

Greetings, I have a hard time creating a large number of user profiles in a database. The data file looks like this : 01/01/80 Mitch Conley . . . . And I need to put the output into: Name: Mitch Surname: Conley Birthday: 01/01/80 Thanks in advance! (3 Replies)
Discussion started by: hemo21
3 Replies

3. Shell Programming and Scripting

Fill missing numbers in second column with zeros

Hi All, I have 100 files with names like this: 1.dat, 2.dat, 3.dat until 100.dat. My dat files look like this: 42323 0 438939 1 434 0 0.9383 3434 120.23 3 234 As you can see in the second column, some numbers are missing. I want to fill those missing places with 0's in all... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

4. Shell Programming and Scripting

fill in last column of data

Hello, I am fairly new to awk, and I have the following problem. My file has missing data in the last column, and the program I am pre-processing this file for cannot interpret correctly shortened rows (it just wraps the data around). Is there a way to force awk to create the same... (6 Replies)
Discussion started by: timert34
6 Replies

5. Shell Programming and Scripting

Fill in missing Data

hello everyone, I have a task to input missing data into a file. example of my data below: Wed Feb 01 09:00:02 EST 2012,,,0.4,0.3,,0.3,,0.3,,0.5,,0.3,,,0.4,0.3, Wed Feb 01 09:00:11 EST 2012,,,,,,,0.2,,,,,,,,,, Wed Feb 01 09:00:22 EST... (23 Replies)
Discussion started by: Nolph
23 Replies

6. Shell Programming and Scripting

Script which fill data in XML file

Hello, I need help for writing a script that fills already generated xml file with data from oracle database and random sequences. For example if we have the following tags: <ns1:message> <ns1:messageId> </ns1:messageId> <ns1:languageCode> </ns1:languageCode>... (10 Replies)
Discussion started by: zb99
10 Replies

7. Shell Programming and Scripting

Fill data if number range is given

Hi I want to get all numbers if number range is given as input. Eg: INPUT FILE 100-105 107 108-112 OUTPUT REQUIRED: 100 101 102 103 104 105 107 108 109 110 111 112 How can I do it using shell? :confused: Thanks in advance. (11 Replies)
Discussion started by: dashing201
11 Replies

8. 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

9. UNIX for Dummies Questions & Answers

Fill csv entire column with content from another text file

I have a csv that looks like this: ,yude-to-nap2,0,0,0,0,0 ,2twis-yude-to-nap2,0,0,0,0,0 ,2tiws-yude-to-nap2,0,0,0,0,0 ,2arcos-yude-to-nap2,0,0,0,0,0 and another file named m1 that has a single line of text as content: Feb 1 15:30:20 How can I fill the whole the empty column of the... (1 Reply)
Discussion started by: RobertoRivera
1 Replies

10. Shell Programming and Scripting

Fill column from previous row

Hi, I have the following content in file ABBR DESC COL3 COL4 COL5 COL6 AAA text desc aaa text text text text text text text text text text text text BBB text desc bbb text text text text text text text text CCC ... (10 Replies)
Discussion started by: bobbygsk
10 Replies
COLUMN(1)						    BSD General Commands Manual 						 COLUMN(1)

NAME
column -- columnate lists SYNOPSIS
column [-tx] [-c columns] [-s sep] [file ...] DESCRIPTION
The column utility formats its input into multiple columns. Rows are filled before columns. Input is taken from file operands, or, by default, from the standard input. Empty lines are ignored. The options are as follows: -c Output is formatted for a display columns wide. -s Specify a set of characters to be used to delimit columns for the -t option. -t Determine the number of columns the input contains and create a table. Columns are delimited with whitespace, by default, or with the characters supplied using the -s option. Useful for pretty-printing displays. -x Fill columns before filling rows. Column exits 0 on success, >0 if an error occurred. ENVIRONMENT
COLUMNS The environment variable COLUMNS is used to determine the size of the screen if no other information is available. EXAMPLES
(printf "PERM LINKS OWNER GROUP SIZE MONTH DAY HH:MM/YEAR NAME " ; ls -l | sed 1d) | column -t SEE ALSO
colrm(1), ls(1), paste(1), sort(1) HISTORY
The column command appeared in 4.3BSD-Reno. BSD
June 6, 1993 BSD
All times are GMT -4. The time now is 06:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy