Extraction & tokenising


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extraction & tokenising
# 1  
Old 04-06-2010
Extraction & tokenising

I have a txt file with entries like follows:

Code:
absdb;ghasgs:agshasgh;asgag:asfhasfh 123;gjasg 563;tusts:gjsqg
absdb;ghasgs:agshasgh;asgag:asfhasfh 123;gjasg 563;tusts:gjsqg
absdb;ghasgs:agshasgh;asgag:asfhasfh 123;gjasg 563;tusts:gjsqg
absdb;ghasgs:agshasgh;asgag:asfhasfh 123;gjasg 563;tusts:gjsqg

and so on ...

i need to write a script to read the 2nd last line of the above file and then tokensie the read line.

Please help.

Last edited by vgersh99; 04-06-2010 at 08:02 AM.. Reason: code tags, please!
# 2  
Old 04-06-2010
kindly post the desired o/p.
BR
Smilie
# 3  
Old 04-06-2010
Quote:
Originally Posted by ahmad.diab
kindly post the desired o/p.
BR
Smilie
It should print sum of the NUMERIC values in the second last row which always occur at specified positions in the second LAST row extracted.
# 4  
Old 04-06-2010
I meant write the final and desired o/p specifying what do you mean by the "second last" row?!?!? Just write the o/p and do not describe it.
# 5  
Old 04-06-2010
Quote:
Originally Posted by skyineyes
It should print sum of the NUMERIC values in the second last row which always occur at specified positions in the second LAST row extracted.
Do you mean the sum of the second last field for the whole file?
# 6  
Old 04-06-2010
Quote:
Originally Posted by Franklin52
Do you mean the sum of the second last field for the whole file?
No. What i meant was as follows:

Code:
fagsfag;dgsqwhdg:qdgjqwd:abdc 4542;gaj:gad 78;gjadgdk

The file has various lines of the above format (seperated by ; : or blank)
I need to pick up the SECOND LAST line of the above file. Then tokensie using COLON SEMICOLON and BLANK as seperator. This will make 5th & 8th values as 4542 & 78 as numeric outputs. The script has to print the sum of these values
# 7  
Old 04-06-2010
Get the SECOND LAST line of the file and do the sum as follows:
Code:
 
row=`sed '1!G;h;$!d' input_file | head -2| tail -1`
##cut the fileds ( only numeric and add it)
echo "$row" | awk -F"[;: ]" '{ for(i=1;i<=NF;i++) {if($i ~ /[0-9]/) sum+=$i }}END{print sum}'


Last edited by panyam; 04-06-2010 at 09:35 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

String Extraction

I am trying to extract a time from the below string in perl but not able to get the time properly I just want to extract the time from the above line I am using the below syntax x=~ /(.*) (\d+)\:(\d+)\:(\d+),(.*)\.com/ $time = $2 . ':' . $3 . ':' . $4; print $time Can... (1 Reply)
Discussion started by: karan8810
1 Replies

3. Shell Programming and Scripting

extraction

I have following input @xxxxxx@ I want to extract what's between @....@ that is : xxxx using SED command (6 Replies)
Discussion started by: xerox
6 Replies

4. Shell Programming and Scripting

Replace & sign to &amp word

Hi, I have text file abc.txt. In this file, I have the following data. Input: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith & Mrs Smith Mr Smith& Mrs Smith Mr Smith &Mrs Smith Output: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith &amp Mrs Smith Mr Smith&amp... (4 Replies)
Discussion started by: naveed
4 Replies

5. Shell Programming and Scripting

replace & with &amp; xml file

Hello All I have a xml file with many sets of records like this <mytag>mydata</mytag> <tag2>data&</tag2> also same file can be like this <mytag>mydata</mytag> <tag2>data&</tag2> <tag3>data2&amp;data3</tag3> Now i can grep & and replace with &amp; for whole file but it will replace all... (4 Replies)
Discussion started by: lokaish23
4 Replies

6. Shell Programming and Scripting

Files extraction - any help ?

Hi Friends, i am new to unix,i have a big doubt/help. I have files in folders SER1 and SER2 with naming convention as below file_2010-03-19.txt and so on the file naming format is file_<date>.txt. I would like to copy the files to directory "Landing" I have entries in a log file log.txt... (5 Replies)
Discussion started by: Gopal_Engg
5 Replies

7. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

8. Shell Programming and Scripting

extraction of last but one char

I need to extract the character before the last "|" in the following lines, which are 'N' and 'U'. The last "|" shouldn't be extracted. Also the no.s of "|" may vary in a line, but I need only the character before the last one. ... (5 Replies)
Discussion started by: hidnana
5 Replies

9. Shell Programming and Scripting

AWK extraction

Hi all, I have a data file from which i would like to extract only certain fields, which are not adjacent to each other. Following is the format of data file (data.txt) that i have, which has about 6 fields delimited by "|" HARRIS|23|IT|PROGRAMMER|CHICAGO|EMP JOHN|35|IT|JAVA|NY|CON... (2 Replies)
Discussion started by: harris2107
2 Replies

10. Shell Programming and Scripting

Tokenising into array (KSH)

Greetings all, I've been getting a little frustrated over my scripts as I'm not too experienced with powerful commands such as awk and sed. Hope to find some guidance here. I need to extract the names of all directories within a specified directory, grab their names and then place each name... (5 Replies)
Discussion started by: rockysfr
5 Replies
Login or Register to Ask a Question