duplicating 1st row of data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting duplicating 1st row of data
# 1  
Old 07-13-2005
duplicating 1st row of data

Hi,

I have data in the following format:

PHP Code:
data1
data2 data3    data4
data5 data6
data7 data8    data9
      data10 
I require the final output to be:

PHP Code:
data1
data1
data1
data1 
i only require the 1st line but I need to replicate it in n rows where n is the number of rows where data exists. In this example, there are 4 rows of data(excluding data1), so I need to replicate data1 in 4 rows.
# 2  
Old 07-13-2005
I have a bash solution here. Not PHP.

Code:
#! /bin/sh

LINE=$(sed -e '1,1p' INPUTFILE)

sed -e '2,s/.*/$LINE/' INPUTFILE > OUTPUTFILE

mv OUTPUTFILE INPUTFILE

Vino
# 3  
Old 07-13-2005
gnu sed:
Code:
sed -n '1h;1!{g;p}'

# 4  
Old 07-14-2005
Hi,

I tried with this:

Code:
sed '1h;g' $file > $TMP/field.A

and it seems ok.

May I know what is the difference with
Code:
sed -n '1h;1!{g;p}'

?
# 5  
Old 07-14-2005
Quote:
In this example, there are 4 rows of data(excluding data1), so I need to replicate data1 in 4 rows.
the difference is the number of rows.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change Data of first ROW

My Input : A.txt 1@A 2@B 3@C 1 4 5 2 4 5 3 4 5 B.txt 1 2 3 A B C 1 4 5 2 4 5 3 4 5 (3 Replies)
Discussion started by: asavaliya
3 Replies

2. Emergency UNIX and Linux Support

[Solved] Mysql - Take data from row and copy it to another row

Sorry if I repost my question in this section, but I'm really in a hurry since I have to finish my work... :( Dear community, I have a table with two rows like: Row1 Row2 ======= ======= 7,3 text 1 1,3 text 2 1,2,3 blabla What i need to do is add/copy... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

3. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

4. Shell Programming and Scripting

Moving data from a specified column/row to another column/row

Hello, I have an input file like the following: 11_3_4 2_1_35 3_15__ _16989 Where '_' is a space. The data is in a table. Is there a way for the program to prompt the user for x1,y1 and x2,y2, where x1,y1 is the desired number (for example x=6 y=4 is a value of 4) and move to a desired spot... (2 Replies)
Discussion started by: jl487
2 Replies

5. Shell Programming and Scripting

Convert row data to column data

Hi Guys, I have a file as follows: a 1 b 786 c 90709 d 99 a 9875 b 989 c 887 d 111 I want: a 1 9875 b 786 989 (3 Replies)
Discussion started by: npatwardhan
3 Replies

6. Shell Programming and Scripting

Add value of each row when each row has different data ype

Guys -- I am noob and I am really strugging on this one. I cant even write the pseudo code for it. I have a file that spits values in individual rows as such: file: user date type size joe 2005-25-09 log 1 joe 2005-25-09 snd 10 joe 2005-25-09 rcd 12 joe 2005-24-09 log 2 joe... (1 Reply)
Discussion started by: made2last
1 Replies

7. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies

8. UNIX for Dummies Questions & Answers

Print out a row of data

hi im completely new at unix so dont hate me for asking what is probably the easiest question ever. below is an extract of some data im processing. the first column is like a counter while the second is an ip address. i need to be able to output the ip address based on which has the largest... (4 Replies)
Discussion started by: Streetrcr
4 Replies

9. Shell Programming and Scripting

first row data into variables

I have a datafile having structure like col1,col2,col3 col1,col2,col3,col4,col5 col1,col2,col3,col4,col5 ..... Can we take only first row of values from datafile and put into respective variable. How col1 can be captured in a variable called v_col1 from unix script. like first row(only)... (1 Reply)
Discussion started by: u263066
1 Replies
Login or Register to Ask a Question