Read from a file then filter the output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Read from a file then filter the output
# 1  
Old 03-02-2009
Read from a file then filter the output

Hi
i need a script which reads a certain file and then display it on the screen.
The thing is i need to filter the display output.

this is an example of the file which is to be loaded in the script.

asdfg1.1.1|98
hjkldfe4.0.3|123
asdzxzvdweradfsdafascv10.0.10|123456789
/ar/bl/ew/as/qw/ds/as.bc.19980123.asdfgt14:adfjeiop2.0.3|112356
/dfd/eras/xzcv/asdf/asdf/adsf/a.d.c.19990124.fasdf:adfadf11.12.13|1234

now i want the output to be like this only

asdfg1.1.1|98
hjkldfe4.0.3|123
asdzxzvdweradfsdafascv10.0.10|123456789
19980123.asdfgt14:adfjeiop2.0.3|112356
19990124.fasdf:adfadf11.12.13|1234

how can i do this thing?
# 2  
Old 03-02-2009
Guessing that this 8 digit number is always the 1st string you want to have printed and is always 8 digits long:

Code:
sed 's/^.*\([0-9]\{8\}\..*\)$/\1/g' infile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

2. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

3. Shell Programming and Scripting

Filter out output and then write to a file

I have a process which writes lots of output to the screen and am capturing it to a file. But the issue is that there are few lines which repeat every second which is causing the file size to be enormous. I am trying to filter out and then run the command but its not working. Can you confirm... (7 Replies)
Discussion started by: rajkumarme_1
7 Replies

4. Programming

Help to filter read through reference file by using c language

Input_file #tmp_2 werweraewghe @tmp_2 123sdfs57a #tmp_1 aewrgheheghe @tmp_1 457awrerfa87 #tmp_4 trtyrghe @tmp_4 8898rtyr2 reference_file #tmp_4 #tmp_1 (14 Replies)
Discussion started by: cpp_beginner
14 Replies

5. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

6. UNIX for Dummies Questions & Answers

How to read entire output from a file?

Hello- I am trying to view a file which is quite large. However, whenever I do 'cat (file name)' it shows me just the half.. I am using Putty to access my server. Also, is it possible to edit a file from a unix system on a 'Gedit for Windows" text editor? Thanks (7 Replies)
Discussion started by: DallasT
7 Replies

7. Shell Programming and Scripting

How to read file and only output certain content

Hi - I have a file containing data like :- cn=tommy,cn=users,c=uk passwordexpirydate=20100530130623z cn=jane,cn=users,c=uk passwordexpirydate=20100423140734z cn=michael,cn=users,c=uk passwordexpirydate=20100331020044z I want to end up with a file that looks like:-... (6 Replies)
Discussion started by: sniper57
6 Replies

8. Emergency UNIX and Linux Support

Read file and change a 0 to a 1 in output

<key>ExcludeSimpleHostnames</key> <integer>0</integer> <key>FTPPassive</key> Need simple command that will change the 0 to a 1 in this file when I grep it, but only for this integer key directly after the ExcludeSimpleHostnames key. I got this output code... (8 Replies)
Discussion started by: glev2005
8 Replies

9. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

10. Shell Programming and Scripting

store output to a file and read from it

Hello all, I need to run snoop command for a period of time (a day) and extract remote host column from it to find out who is accessing my server. When I run the following on the command line it works snoop -port 22 | awk '{print $3}' but when I do snoop -port 22 | awk '{print $3}' | while... (2 Replies)
Discussion started by: afadaghi
2 Replies
Login or Register to Ask a Question