Print values of a string froma file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Print values of a string froma file
# 1  
Old 01-28-2009
Print values of a string froma file

Hi,

I have a problem in getting values of a specific string on a file, can you please help me what command or script that I will use to get it?

I have a file with the following sample contents. I need to print the values of time. The time sometimes appears on column 2 or column 3. Please help me how to get the values of time. Thanks in advance!

Date=20090128,time=11:30,folder=/
Date=20090129,time=10:00,folder=/tmp
Date=20090128,file=/tmp,time=09:00

sample output:
11:30
10:00
09:00
# 2  
Old 01-28-2009
nawk -f au.awk myFile

au.awk:
Code:
BEGIN {
   FS="[=,]"
}
{
   for(i=1;i<=NF; i++)
      if ($i == "time") {
        print $(i+1)
        next
   }
}

# 3  
Old 01-28-2009
Print values of a string froma file

Hi Vgersh99,

I tried it, it's working! Thanks a lot for your help! You're really great! Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

2. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

3. Shell Programming and Scripting

Extract values froma line in file

p.txt T|DCNT=100|RECCHK=22222.2|PERCHK=32323|# I want to extract the value of 100 22222.2 and 32323 and assign it to variable x1,y1,z1 x=`cut -f2 -d "=" p.txt` x1=`echo $x | cut -f1 -d "|" ` y=`cut -f3 -d "=" p.txt` y1=`echo $y | cut -f1 -d "|" ` z=`cut -f4 -d "=" p.txt` z1=`echo $z... (3 Replies)
Discussion started by: w020637
3 Replies

4. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

5. UNIX for Advanced & Expert Users

Awk to print values of second file

Hello, I have a data file with 300,000 records in it, and another file which contains only the line numbers of roughly 13,000 records in the data file which have data integrity issues. I'm trying to find a way to print the original data by line number identified in the second file. How can I do... (2 Replies)
Discussion started by: peteroc
2 Replies

6. Shell Programming and Scripting

Print required values at end of the file by using AWK

I am looking help in awk, quick overview. we will get feed from external system . The input file looks like below. Detail Id Info Id Order Id STATUS Status Date FileDetail 99127942 819718 CMOG223481502 PR 04-17-2011 06:01:34PM... (7 Replies)
Discussion started by: dvrbabu
7 Replies

7. Shell Programming and Scripting

remove values of a file one by one from 2nd file and then print the remaining values of 2nd file

Hi all, I have 2 files. One contains only 1 column and other one contains 2 columns, let say 1_col.txt and 2_col.txt respectively. Here, I will try to explain with an example. Input files : 1_col.txt 2_col.txt a a b x a c p ... (5 Replies)
Discussion started by: AshwaniSharma09
5 Replies

8. Shell Programming and Scripting

Remove a non-specific word froma file

Hi All, I am encountering a problem while removing a string from a file. Actually, i have done this thing before using sed to replace the word but this time word is not specfic. its value is changing with each file. e.g. %HD% Serial Number list per DN required. +3... (2 Replies)
Discussion started by: apjneeraj
2 Replies

9. UNIX for Dummies Questions & Answers

how to extract a substring froma file

hi all, I'm really newbie on this and I need some help. how is the best way to extract a strig or substring from a each line in a file. e.g. I want to print only this ERROR=JUD+the followed numbers from one line like this one, considering the numbers change related to different errors ... (1 Reply)
Discussion started by: morena
1 Replies
Login or Register to Ask a Question