Get the number from the txt file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Get the number from the txt file
# 1  
Old 01-09-2008
Get the number from the txt file

Hello Guy,

I have the following information in the sample.txt, can i get the number and output into sample2.txt


-[000039:000008135]
-[000040:000008329]
-[000042:000008723]
-[000045:000009368]
-[000000:000010750]
-[000053:000011169]
-[000054:000011401]
-[000062:000013107]
-[000098:000020436]
-[000106:000022044]
-[000112:000023322]
-[000119:000024890]
-[000141:000029568]
-[000153:000032264]
-[000154:000032458]
-[000157:000033038]
-[000158:000033232]
-[000164:000034534]
-[000166:000034959]
-[000168:000035389]
-[000169:000035583]
-[000170:000035777]
-[000178:000037404]
-[000179:000037598]
-[022181:000038015]

output:
39
40
42
45
0
53
54
62
98
106
112
119
141
153
154
157
158
164
166
168
169
170
178
179
22181

thx!!
# 2  
Old 01-10-2008
happyv,
what have you tried? you had 200+ post, so i expected you to have tried something.

Last edited by ghostdog74; 01-10-2008 at 12:08 AM..
# 3  
Old 01-10-2008
Java

Code:
cut -d '[' -f 2 < sample.txt | cut -d ':' -f 1 | bc > sample2.txt

# 4  
Old 01-10-2008
Code:
awk -F":" '{tmp=substr($1,3,6);print tmp*1;}' filename >sample.txt

# 5  
Old 01-10-2008
Code:
awk -F"[:-\[\]" '{ print $2 * 1}' filename > output.filename

# 6  
Old 01-10-2008
Code:
awk '{print $2+0}' FS="[:[]" data

Or Smilie

Code:
awk '!($0=$2+0)||1' FS="[:[]" data

# 7  
Old 01-10-2008
for very large files and assuming always 6 characters
Code:
awk  '{print substr($0,3,6)}' file  | bc > outfile

or
Quote:
Originally Posted by Smiling Dragon
Code:
cut -d '[' -f 2 < sample.txt | cut -d ':' -f 1 | bc > sample2.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split a txt file on the basis of line number

I have to split a file containing 100 lines to 5 files say from lines ,1-20 ,21-30 ,31-40 ,51-60 ,61-100 Here is i can do it for 2 file but how to handle it for more than 2 files awk 'NR < 21{ print >> "a"; next } {print >> "b" }' $input_file Please advidse. Thanks (4 Replies)
Discussion started by: abhaydas
4 Replies

2. Shell Programming and Scripting

Linux Commands needed for replacing variable number of spaces with a single , in a txt file

Hi I want to read a text file and replace various number of spaces between each string in to a single "," or any other character .Please let me know the command to do so. My input file is a txt file which is the output of a SQL table extract so it contains so many spaces between each column of the... (2 Replies)
Discussion started by: Hari Prasanth
2 Replies

3. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

4. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

5. UNIX for Dummies Questions & Answers

how to generate random number as as the first column of a txt file

Dear all, I have a question. I have a txt file say 4000 rows X 1800 Column. I 'd like to creat a new column as the first column which is a column of random numbers (n=4000) thanks a lot! Lin (2 Replies)
Discussion started by: forevertl
2 Replies

6. Shell Programming and Scripting

ksh program that finds the lowest number in a .txt file

i am having a problem finding the lowest number after punching in a bunch of numbers in the .txt file but its probably the way i have the code set up. help please! (4 Replies)
Discussion started by: tinsteer
4 Replies

7. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

8. Shell Programming and Scripting

Number of *.txt files which have over n lines?

Can you help me please? I know that wc -l *.txt gives you the number of lines in each file. But how can i count the files that have over n lines? (4 Replies)
Discussion started by: dark_knight
4 Replies

9. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies

10. AIX

Printing a number of copies of a txt file

Hi, We have an application running on AIX5.3 that generates text files that are sent to be printed using the lp command. The user can specify the number of copies they want printed, but only one copy ever gets printed. I've checked the lp command that is used, and it correctly specifies... (5 Replies)
Discussion started by: stebradshaw
5 Replies
Login or Register to Ask a Question