grep data and add to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep data and add to file
# 1  
Old 09-20-2006
grep data and add to file

Hey,
i need to write a bash program that can run through a liste of files and then pick up the last access time and modification times and then write them to a file.
If anyone has done something like this before, please help me.

Thanks
# 2  
Old 09-20-2006
#access time
ls -ul | grep "filename" | awk '{ print $9, $6 ,$7, $8, }' > fl
#modification time
ls -l | grep "filename" | awk '{ print $9, $6 ,$7, $8, }' >>fl
# 3  
Old 09-20-2006
Hi, Anbu, can you explain what mean this code,
sorry I'm new in unix and want learn more about unix.. Smilie

Thank you
# 4  
Old 09-21-2006
Code:
ls -ul 

display all files and folders in current directory with last access time and pass this output to grep through pipe

Code:
grep "filename" 

searches for this filename in the output of above command and display that line if it finds the filename and pass this output to awk command thro pipe

Code:
awk '{ print $9, $6 ,$7, $8, }' 

display ninth field which is filename and then prints month , day and time of last access and redirecting this output to some file "fl"

Code:
ls -l 

display all files and folders in current directory with last modification time and pass this output to grep through pipe
# 5  
Old 09-21-2006
ls -ul | grep "filename" | awk '{ print $9, $6 ,$7, $8, }' > fl

ls -ul |awk '/filename/{print $9, $6 ,$7, $8, }' > fl

Why bother with grep?

ls -ul |awk '!/filename/{print $9, $6 ,$7, $8, }' > fl (ignore this file)
# 6  
Old 09-25-2006
Thanks for all the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using grep to select data from file

Hello all, Once again I need to call upon the masters for help. I have a file called endpoint_data. IN that file I have groups of endpoints. However all I need from the file is this.... ENDPOINT NAME = SIPWOODSBC SIG PRI FQDN/IP ADDRESS/DOMAIN NAME = 10.xxx.xxx.xxx SIG SEC... (4 Replies)
Discussion started by: jay11789
4 Replies

2. Shell Programming and Scripting

Remove data from grep command using the pattern in the file

Hi, I writing a shell program to remove the data from output of the find which matches a list in a file I am using the below find command to get the list of files x=`find . -name test*.dat` the output of the find command is as follows test1.dat test2.dat test3.dat test4.dat... (4 Replies)
Discussion started by: pals70423
4 Replies

3. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

4. Shell Programming and Scripting

add more data to existing data in a file

Hi all, I need help to add additional data from file2 to existing data in file 1 using awk, sed or perl. the ID in file 1 should match against field $3 in file2 file1 #this is a new game ID HR_1 BASE1 30 BASE2 37 DETAIL No TYPE L @@ ID HR_10 BASE1 6030 BASE2 ... (4 Replies)
Discussion started by: redse171
4 Replies

5. UNIX for Dummies Questions & Answers

awk and grep to search a data file

Hi everyone, I cannot figure out how I can do a search in a file that has Names, Surnames, Addresses and telephone number of a number of people. Here is an example of the data file Daisy:Hunter:490 London Road:07313196347 Richard:Murphy:983 Main Road:07002625997 Isobel:Magnusson:133 London... (1 Reply)
Discussion started by: philipisaia
1 Replies

6. Shell Programming and Scripting

i want to grep some data from other file

helo all i have 2 files. and i want to grep the contents of first file from the 2nd file. but these files are too large contaning lacks of lines . i'm using for loop but it takes so moch times . is there any other sol. i'm using this code " for var in `cat succ_migrated` do grep $var... (4 Replies)
Discussion started by: dodasajan
4 Replies

7. Shell Programming and Scripting

read in variable data from another file - grep

Hello! I think this should be an easy solution. I have a large file with many fields of data. The first field has a unique identifier (a subject number) for every record for a chunk of data. Something like this: There were ten experimental conditions (ec), but the ec is identified by only... (11 Replies)
Discussion started by: ccox85
11 Replies

8. Shell Programming and Scripting

Big data file - sed/grep/awk?

Morning guys. Another day another question. :rolleyes: I am knocking up a script to pull some data from a file. The problem is the file is very big (up to 1 gig in size), so this solution: for results in `grep "^\ ... works, but takes ages (we're talking minutes) to run. The data is held... (8 Replies)
Discussion started by: dlam
8 Replies

9. Shell Programming and Scripting

no data redirected to a file with top and grep - why?

HI all, I want to capture cpu data in batch mode of "top" command and redirect to a file like this: top -b > cpu.dat it works! But I want to capture only Cpu lines, so i have: top -b | grep ^Cpu >cpu.dat Then I got an empty output file. Why? Could somebody explain and help me to make it... (15 Replies)
Discussion started by: fongthai
15 Replies

10. Shell Programming and Scripting

Pipe Data From Grep Into A File

I am somewhat of a novice at unix scripting and I need a little help. Here is what im trying to do: I am trying to figure out how to pipe the following grep results into a file. /source/programs: grep "WSBL020" W* WBMB991.cbl: COPY WSBL020. WDCB003.cbl: COPY... (4 Replies)
Discussion started by: katinicsdad
4 Replies
Login or Register to Ask a Question