Insert first line of a file to first column of remaining files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert first line of a file to first column of remaining files
# 1  
Old 07-27-2008
Insert first line of a file to first column of remaining files

I want to extraxt data from a html table

the html file is downloaded from

UG / PG Univ - Exam.Results April/May 2008

After processing the html file using sed i got the output like this

11305106082,RANJANI R,
CS1251,20,69,P
CS1302,20,45,P
EC1006,20,52,P
EC1351,20,53,P
EC1352,20,47,P
EC1353,20,80,P
EC1354,20,78,P
EC1355,20,78,P
GE1352,20,74,P
MG1351,20,52,P

11305106082,RANJANI R,CS1251,20,69,P
11305106082,RANJANI R,CS1302,20,45,P
11305106082,RANJANI R,EC1006,20,52,P
11305106082,RANJANI R,EC1351,20,53,P
11305106082,RANJANI R,EC1352,20,47,P
11305106082,RANJANI R,EC1353,20,80,P
11305106082,RANJANI R,EC1354,20,78,P
11305106082,RANJANI R,EC1355,20,78,P
11305106082,RANJANI R,GE1352,20,74,P
11305106082,RANJANI R,MG1351,20,52,P

what i have to do, help me

Last edited by a_artha; 07-29-2008 at 02:29 PM..
# 2  
Old 07-27-2008

I'd use awk, not sed, as it is easier to understand.

However, since most of the necessary is already done, I'll just add another couple of lines:

Code:
sed -n -e "/Brown/,/<\/table>/p" 11305106082.html |
sed "/Register/d;/Name/d;/blue/d;/^$/d;s/> />/g;s/^[ \t]*//;s/[ \t]*$//" |
sed -e :a -e N -e "s/<\/td>\n/,/;s/<\/th>\n/,/" -e ta |
sed -e :a -e "s/<[^>]*>//g;/</N;//ba" |
sed "/^$/d" | {
 read line
 sed  "/.../ s/^/$line/"
}

# 3  
Old 07-27-2008
Code:
perl -ne 'if($.==1){$_ =~ tr/\n//d;$t=$_;}else{print $t,$_;}' file

# 4  
Old 07-28-2008
Thank you Mr. johnson.
it is working fine. if possible pl post me the awk script to extraxt data from html file
# 5  
Old 07-28-2008
Code:
awk '{
if(NR==1)
	t=$0
else
	print t""$0
}' file

# 6  
Old 07-28-2008
Thank you Summer_cherry
first one is working fine
second one is not checked
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

2. Shell Programming and Scripting

Awk: duplicate column and print remaining as is

Hello there I'd like to make a copy of 2nd column and have it printed in place of column 1. Remaining columns are needed as it. test data: ProbeSet GeneSymbol X22565285 X22566285 ILMN_1050008 MYOCD 6.577 7.395 ILMN_1050014 GPRC6A 6.595 6.668 ILMN_1050017 ... (2 Replies)
Discussion started by: genome
2 Replies

3. Shell Programming and Scripting

Get remaining line after string match

Want to get the remaining line after pattern match Here it starts - executed commands : - pattern to identify 100:27:500:1:34:END Required output:100:27:500:1:34:END awk '{if(/pattern to identify/) print $2}' < file I have used above code and it not giving... (3 Replies)
Discussion started by: rozee
3 Replies

4. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

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

6. Shell Programming and Scripting

Split a file into multiple files based on line numbers and first column value

Hi All I have one query,say i have a requirement like the below code should be move to diffent files whose maximum lines can be of 10 lines.Say in the below example,it consist of 14 lines. This should be moved logically using the data in the fisrt coloumn to file1 and file 2.The data of first... (2 Replies)
Discussion started by: sarav.shan
2 Replies

7. UNIX for Dummies Questions & Answers

insert a column into file

hi everybody! Could u show me how to do following: I have files (in total 22) .txt that contain one column of values (the total number of values varies from file to file from 40.0000 to 10.000). For example: 742429 758311 995669 1008567 1011278 1011521 1020428 1021403 ... And I need... (2 Replies)
Discussion started by: kush
2 Replies

8. Shell Programming and Scripting

compare files and remove a line from a file if first column is greater than 25

my files are as follows fileA sepearated by tab /t 00 lieferungen 00 attractiop 01 done 02 forness 03 rasp 04 alwaysisng 04 funny 05 done1 fileB funnymou120112 funnymou234470 mou3raspnhdhv rddfgmoudone1438748 so all those record which are greater than 3 and which are not... (4 Replies)
Discussion started by: rajniman
4 Replies

9. Shell Programming and Scripting

Insert new line based on numerical number of column

My input file: Class Number Position Range 1 Initial 50 1 Initial 50 2 Terminal 150 2 Terminal 20 2 Single 10 3 Single 20 4 Double 50 5 Initial 50 5 Initial 60 Class Number... (11 Replies)
Discussion started by: patrick87
11 Replies

10. Shell Programming and Scripting

insert a variable in the last column of a file

i want to insert a variable in the last column of a file, the columns are separated by "|". I want to insert the variable in everyline of the file . (7 Replies)
Discussion started by: dineshr85
7 Replies
Login or Register to Ask a Question