Sponsored Content
Full Discussion: Help in writing script
Top Forums Shell Programming and Scripting Help in writing script Post 302473371 by DGPickett on Friday 19th of November 2010 04:25:27 PM
Old 11-19-2010
Narrative: Suppose I am searching for 'printf(' family calls in my C source directory 'mysrc'.
  1. I open a subshell (...) so I am not changing the $PWD of the caller when I cd.
  2. I put those two parameters into variables.
  3. I list all the c files, newest first,
  4. into sed, which substitutes for beginning of line ^ not-space [^ ] any number of times * one space (5 times) then capturing \(..\) up to the last space as one field (the time part, but this does not work well for ls -l on sym links, just simple files) and everything else (the file name) as the second field. Sed throws away the first 5 fields (not captured), rewrites the two fields into an echo command with an embedded grep -c to count the references, a tab to accommodate varying number width from grep -c, and the captured fields.
  5. sed quits after converting 20 lines.
  6. The dynamically created script goes into ksh.
Code:
 
(
export   astring="printf("   lib_dir=mysrc 
cd $lib_dir
ls -lt *.c | sed '
  s/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *\(.*\) \(.*\)/echo $( grep -c "'"$astring"'" <\2 )"     \1 \2"/
  20q
 ' | ksh
)
1       Nov 18 17:20 pctbin.c
4       Nov 12 12:13 xdemux.c
2       Nov 12 11:32 fgets_eof.c
0       Nov 10 16:58 cps.c
0       Nov  3 09:30 tps.c
0       Nov  3 09:14 tcs.c
0       Oct 28 14:24 usleep2.c
0       Oct 18 11:03 allwait.c
1       Oct 15 16:58 fwcl.c
4       Oct 14 14:25 fxargs2.c
10      Oct 14 12:20 tm2tm.c
12      Oct 14 10:35 autotab.c
5       Jul 23 15:25 undelim.c
0       Jun 15 12:36 lineso2.c
0       Jun 15 11:03 lineso.c
2       Jun  3 10:52 realpath.c
0       May 28 10:28 pt2h.c
0       May 25 08:57 ghead.c
32      May 25 08:54 string_functions.c
1       May 25 08:54 psal.c


Last edited by DGPickett; 11-20-2010 at 12:25 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need help writing a script

Hello everyone. Well, I will get right to the point. I am new to Perl and trying to learn it as much as I can. I have been assigned the task of writing a perl script to extract information from firewall logs. Like I said, I am new to Perl and I am having a tough time because I think what I am... (3 Replies)
Discussion started by: tarballed
3 Replies

2. Shell Programming and Scripting

Writing Script?

Anyone have an example of a simple shell script that solicits a (Y)es or (N)o response from the user. If the response is 'Y' display a message on the screen that thanks the user for the positive response. If the response is 'N' display a message that thanks the user for the negative response. If... (15 Replies)
Discussion started by: wmosley2
15 Replies

3. UNIX for Dummies Questions & Answers

help for writing a script

Hi, I need help writing a unix script to change the time in the server automatically when it reaches a specified time. Only on the 14th of april, when the time becomes midnight (00:00:00), I need the server to change the time automatically to 23:30:00 and start working on as usual with a... (2 Replies)
Discussion started by: amodha
2 Replies

4. Shell Programming and Scripting

help writing script

hi all i am having a file(a fixed length file) of 28 bytes.The file has account number from 5th place to next 16 digits. the file looks like below, 58331600563588885696ACXT5263 58331600563588885697ACXT5263 58331600563588885698ACXT5263 i want to write a script which will extract the... (8 Replies)
Discussion started by: dr46014
8 Replies

5. UNIX for Dummies Questions & Answers

Need help writing this script

Here is the script I am trying to write along with my answer I wrote. Please help me understand why it doesn't work. Create an executable script file called "newname" that will perform the followings: 1. Rename a file upon the user's request. If the file exists, prompt the user for... (1 Reply)
Discussion started by: wiggles
1 Replies

6. Shell Programming and Scripting

Help me in writing the script

Hi, I have written a script which converts a give hexdecimal value to binary value in perl. But now, the problem is I should read every bit of it ( if its 10101010, i should read the value in each position and if the value in that position is 1 i should print a string and should exit if its... (1 Reply)
Discussion started by: prakashreddy
1 Replies

7. Shell Programming and Scripting

Please help me in writing my script

hello all, I have a script, used to search for the strings from the set of 5 similar pattern file from the log dir. So here it goes . The input parameter is a part of the file name. When during the script execution, the script should parse the input parameter to original file's with the same... (0 Replies)
Discussion started by: baraghun
0 Replies

8. Red Hat

writing a script

Dear Madam/Sir Who can help me with writing a script doing the following? 1- Read names of files (only files with special name format let say initially they have the same file name start like TT*) 2- Then create an empty files with the same names have been read in step one but with extension... (1 Reply)
Discussion started by: m.nageeb
1 Replies

9. Shell Programming and Scripting

I need help writing this script

:wall: Can't seem to figure out how to fix this please help its not starting over like I would like it to When I enter in "Date" or "Time" nothing comes Also if you can tell me the commands for the other 3 stuff that would be much appreciated #!/bin/bash clear while ; do echo... (8 Replies)
Discussion started by: nowruzr
8 Replies

10. How to Post in the The UNIX and Linux Forums

Help with script writing?

I am new for script writing. I have a file named as name.dat and contain numbers with different rows and columns. I want to sum numbers at one row with that of at another row; like row1 + row101 + row 201, with corresponding columns. Any one can help me to write a script for this operation. ... (1 Reply)
Discussion started by: kumnegert
1 Replies
GREP(1) 						      General Commands Manual							   GREP(1)

NAME
grep - search a file for lines containing a given pattern SYNOPSIS
grep [-elnsv] pattern [file] ... OPTIONS
-e -e pattern is the same as pattern -c Print a count of lines matched -i Ignore case -l Print file names, no lines -n Print line numbers -s Status only, no printed output -v Select lines that do not match EXAMPLES
grep mouse file # Find lines in file containing mouse grep [0-9] file # Print lines containing a digit DESCRIPTION
Grep searches one or more files (by default, stdin) and selects out all the lines that match the pattern. All the regular expressions accepted by ed and mined are allowed. In addition, + can be used instead of * to mean 1 or more occurrences, ? can be used to mean 0 or 1 occurrences, and | can be used between two regular expressions to mean either one of them. Parentheses can be used for grouping. If a match is found, exit status 0 is returned. If no match is found, exit status 1 is returned. If an error is detected, exit status 2 is returned. SEE ALSO
cgrep(1), fgrep(1), sed(1), awk(9). GREP(1)
All times are GMT -4. The time now is 01:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy