Sponsored Content
Top Forums Shell Programming and Scripting Read a File line by Line in unix Post 302546725 by burwood on Friday 12th of August 2011 02:58:47 AM
Old 08-12-2011
Read a File line by Line in unix

Hi ,

I have few files in a directory .
I need to read all the files in that direcory and search for certain criteria in each file and write into a outputfile.
I am also writing the each file name to the outputfile .
For the above criteria , i have written the script.
*****************************************************
Code:
#!/bin/sh
rm -f  LookupFile.txt
for i in `ls *.log`
do
echo -ne $i >> LookupFile.txt
awk  '/CMN_1716 Lookup/
     /Creating Lookup Cache/
     /Lookup cache creation completed/' $i >> LookupFile.txt
echo  $i >> LookupFile.txt
done

***********************************************************
o/p for the above script
Code:
LookupFile.txt--Filename
 

(sessionlogname1)TRANSF_1_1_1> CMN_1716 Lookup [lookuptransformationname1] uses database connection [Relational:DataWarehouse] in codepage [UTF-8 encoding of Unicode]
TRANSF_1_1_1> DBG_21079 Creating Lookup Cache : (Fri Aug 05 00:46:31 2011)
TRANSF_1_1_1> DBG_21294 Lookup cache creation completed : (Fri Aug 05 00:47:15 2011)
TRANSF_1_1_1> CMN_1716 Lookup [lookuptransformationname2] uses database connection [Relational:DataWarehouse] in codepage [UTF-8 encoding of Unicode]
TRANSF_1_1_1> DBG_21079 Creating Lookup Cache : (Fri Aug 05 00:47:16 2011)
TRANSF_1_1_1> DBG_21294 Lookup cache creation completed : (Fri Aug 05 00:47:16 2011)
sessionlogname1
(sessionlogname2)TRANSF_1_1_1> CMN_1716 Lookup [lookuptransformationname] uses database connection [Relational:DataWarehouse] in codepage [UTF-8 encoding of Unicode]
TRANSF_1_1_1> DBG_21079 Creating Lookup Cache : (Mon Aug 08 03:42:15 2011)
TRANSF_1_1_1> DBG_21294 Lookup cache creation completed : (Mon Aug 08 03:42:15 2011)
sessionlogname2

*****************************************
In the second stage, i need to read the LookupFile.txt file line by line and get the required information
for each lookup transformation into one line and write to a file.
So the file should be in the below mentioned format.

--------Final file structure------------
Code:
Filename1,lookuptransformationname1,cache creation time(Fri Aug 05 00:46:31 2011),cache completed time(Fri Aug 05 00:47:15 2011)
Filename1,lookuptransformationname2,Fri Aug 05 00:47:16 2011,Fri Aug 05 00:47:16 2011
Filename2,lookuptransformationname,Mon Aug 08 03:42:15 2011,Mon Aug 08 03:42:15 2011

So for each lookuptransformation in the file , it should write into one line with the assoiciated information.

Please help me in this issue .
Thanks,
Burwood

Last edited by pludi; 08-12-2011 at 06:00 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

2. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

3. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

4. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

5. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

6. Shell Programming and Scripting

How to read a file, line by line in UNIX script?

#!/bin/bash file1="yxd" for file in `cat file3.txt`; do cat $file1 | awk '{split($1,dp,"."); lend=length(dp); if(lend>2) { dom=dp"."dp; split($2,ipl,","); for(i=1; i<=length(ipl); i++) { if(ipl~/:/) { if(ipl~/:/) i++; rip=ipl; i++; raq=ipl; rtq=0; si=i+4; for(;i<si;i++) rtq+=ipl; rsub="";... (2 Replies)
Discussion started by: veeruasu
2 Replies

7. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

8. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

9. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

10. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies
IXPC(1) 						      General Commands Manual							   IXPC(1)

NAME
ixpc - ixp client SYNOPSIS
ixpc [-a address] action file ixpc -v DESCRIPTION
Overview ixpc is a client to access a 9P file server from the command line or from shell scripts. It can be used to configure wmii(1). Options -a address Lets you specify the address to which ixpc will establish a connection. If this option is not supplied, and the environment variable IXP_ADDRESS is set, ixpc will use this value as its address. Currently, the address can only be a unix socket file or a tcp socket. The syntax for address is taken (along with many other profound ideas) from the Plan 9 operating system and has the form unix!/path/to/socket for unix socket files, and tcp!hostname!port for tcp sockets. -v Prints version information to stdout, then exits. The syntax of the actions is as follows: write Writes the supplied data from the standard input to file, overwriting any previous data. The data to be written is arbitrary and only gains meaning (and restrictions) when it is interpreted by wmiiwm(1). See EXAMPLES below. xwrite The same as write, but the data is taken from subsequent arguments, rather than the standard input. create Creates file or directory. If the file exists, nothing is done. ls Lists files and directories. read Reads file or directory contents. remove Removes file or directory tree. ENVIRONMENT
IXP_ADDRESS See above. EXAMPLES
ixpc ls / This prints the root directory of the wmii filesystem, if IXP_ADDRESS is set to the address of wmii. For more information about the contents of this filesystem, see wmiiwm(1). ixpc xwrite /ctl quit Write 'quit' to the main control file of the wmii filesystem, effectively leaving wmii. ixpc write /keys < keys.txt Replace the contents of /keys with the contents of keys.txt SEE ALSO
wmii(1) http://www.cs.bell-labs.com/sys/man/5/INDEX.html ixpc-VERSION IXPC(1)
All times are GMT -4. The time now is 01:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy