handling with grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting handling with grep
# 8  
Old 04-27-2012
Question

file content is

Code:
-rw-r-----    1 root     root            0 Mar 29 00:00 ^[[00mtgp00290312.dat.old^[[00m^M
-rw-r-----    1 root     root          684 Mar 29 01:00 ^[[00mrcp00290312.dat.old^[[00m^M
-rw-r-----    1 root     root           96 Mar 29 01:12 ^[[00mtgp01290312.dat.old^[[00m^M
-rw-r-----    1 root     root           76 Mar 29 01:22 ^[[00mrcp01290312.dat.old^[[00m^M
-rw-r-----    1 root     root            0 Mar 29 02:00 ^[[00mtgp02290312.dat.old^[[00m^M
-rw-r-----    1 root     root           76 Mar 29 02:07 ^[[00mrcp02290312.dat.old^[[00m^M
-rw-r-----    1 root     root            0 Mar 29 03:00 ^[[00mtgp03290312.dat.old^[[00m^M
-rw-r-----    1 root     root           76 Mar 29 03:22 ^[[00mrcp03290312.dat.old^[[00m^M
-rw-r-----    1 root     root            0 Mar 29 04:00 ^[[00mtgp04290312.dat.old^[[00m^M
-rw-r-----    1 root     root            0 Mar 29 04:00 ^[[00mrcp04290312.dat.old^[[00m^M
-rw-r-----    1 root     root            0 Mar 29 05:00 ^[[00mtgp05290312.dat.old^[[00m^M
-rw-r-----    1 root     root            0 Mar 29 06:00 ^[[00mtgp06290312.dat.old^[[00m^M
-rw-r-----    1 root     root          152 Mar 29 06:00 ^[[00mrcp05290312.dat.old^[[00m^M
-rw-r-----    1 root     root            0 Mar 29 07:00 ^[[00mtgp07290312.dat.old^[[00m^M
-rw-r-----    1 root     root          760 Mar 29 07:00 ^[[00mrcp06290312.dat.old^[[00m^M
-rw-r-----    1 root     root         3496 Mar 29 08:00 ^[[00mrcp07290312.dat.old^[[00m^M
-rw-r-----    1 root     root          288 Mar 29 08:57 ^[[00mtgp08290312.dat.old^[[00m^M
-rw-r-----    1 root     root         4940 Mar 29 09:00 ^[[00mrcp08290312.dat.old^[[00m^M
-rw-r-----    1 root     root           96 Mar 29 09:42 ^[[00mtgp09290312.dat.old^[[00m^M
-rw-r-----    1 root     root         8512 Mar 29 10:00 ^[[00mrcp09290312.dat.old^[[00m^M
-rw-r-----    1 root     root          192 Mar 29 10:56 ^[[00mtgp10290312.dat.old^[[00m^M


in
Quote:
cat filecount.txt
the contents was showing ok but in vi editor some fileds are coming extra

Quote:
-rw-r----- 1 root root 192 Mar 29 10:56 ^[[00mtgp10290312.dat.old^[[00m^M
and there is one more problem

in the counter it is repeating the values

as

out put should be
Code:
010212*
020212*

but its taking
Code:
010212*
020212*
010212*
020212*

my code for counter is

Code:
typeset -Z2 i
i=1
d2=`expr $d1 + 1`       #########d1 is the date as per input(01,02,...,31)#####
while [ $i -lt $d2 ]
do

o="$i$m1$y1*"             ##########m1 is month and y1 is year (these are user inputs)########
echo "$o"

o1="$i-$m1-$y1,"
echo "$o1,\c">>filecount1.txt         ########get all the dates in single line comma separated ###
echo "\n">>filecount1.txt
grep  nc*"$o" filecount.txt >>filecount1.txt    #####get the count for each date file##########

i=`expr $i + 1`

done

# 9  
Old 04-27-2012
You are correct, it should be one awk.

Code:
awk -F " " '$9 ~ /^rcm.*200212/ {print $9}' filename

Though I'll have another crack at it now that I can see his data.
# 10  
Old 04-27-2012
Quote:
Originally Posted by sagar_1986
in the contents was showing ok but in vi editor some fileds are coming extra
How was this listing saved? It is extremely odd, full of escape sequences for colors, which would mean it was saved with script or something odd like that, and also full of carriage returns, indicating it may have been re-saved in windows somewhere along the way!

Is it possible to get the original listing or make a new one? You're trying to work around problems you really shouldn't have to.
# 11  
Old 04-27-2012
The input data you gave contains no lines that actually match the lines you want. Smilie

So I still can't tell if it works, how could I possibly test it? Smilie

...But might be closer to dealing with your data. But perhaps something like this:

Code:
awk '{ gsub(/\033\[00m/,""); sub(/\r/, ""); $0=$9 } /rcm.*200212/'

This User Gave Thanks to Corona688 For This Post:
# 12  
Old 04-28-2012
dear Corona688

It works perfect....thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

2. UNIX for Dummies Questions & Answers

File handling

I have a file 1 298167 298168 1093209 1093210 1422663 I want to write a code where in I want to read contents of above file like first read is 1 second read is 298167 Substract second read from first and if this is greater than or less than 99,999. Similarly I want to traverse thru... (3 Replies)
Discussion started by: Guru148
3 Replies

3. Shell Programming and Scripting

Handling string

I have to source a file "varname" the content of varname file is like this: #ani ani1 = abc_ani ani2 = def_ani #sham sham1 = abc_sham sham2 = abc_sham Now i need to extract any line containing "ani: in it. And then store the extracted info in a file. (3 Replies)
Discussion started by: animesharma
3 Replies

4. Programming

Exception Handling C++

Hello All, I have a question ....which I am totally confused about! If I have a fxn foo in a program which returns a logical value. But it has a posssiblity to throw some exception. Now my exception handler returns a value as a string stating why the exception occured. But my... (1 Reply)
Discussion started by: mind@work
1 Replies

5. Shell Programming and Scripting

Handling Variables

Experts & Learned Folks, Im asking for a solution that Im not sure as how to handle. Owing to reasons of anonymity, I masked some of the text that Im searching for here. Ok. Here it goes. I have an output of script like below - THIS IS THE DATALEFT ON FIRST LINE WITH COUNT 75. THIS IS THE ... (7 Replies)
Discussion started by: ManoharMa
7 Replies

6. UNIX for Advanced & Expert Users

please help me in file handling

sir i have to get first line from a file for example >cat file1 abc zxc asd adsf from that file1 i need only first line expected result >abc please help me ! (1 Reply)
Discussion started by: ponmuthu
1 Replies

7. Shell Programming and Scripting

String handling

shell script to input two strings and stripe out the second string from the first string either from the beginning or from the end as per the user's choice (3 Replies)
Discussion started by: Priyanka Bhati
3 Replies

8. Programming

Signal Handling

Hi folks I'm trying to write a signal handler (in c on HPUX) that will catch the child process launched by execl when it's finished so that I can check a compliance file. The signal handler appears to catch the child process terminating however when the signal handler completes the parent... (3 Replies)
Discussion started by: themezzaman
3 Replies

9. Programming

File Handling in C

Hi all, I have a problem in handling files through C. here is the problem im having: i will query the database (for instance consider employees table ) for empno,ename,job,salary fields.The query returns me some 100 of rows. now i need to place them in a file in row wise pattern as they... (3 Replies)
Discussion started by: trinath
3 Replies

10. UNIX for Dummies Questions & Answers

Parameter handling

Hi, i would like to ask that: If u need to do something like this: counter = 1; so that $($counter) = $1, and when u counter++, $($counter) will become $2. How can we do this? (1 Reply)
Discussion started by: AkumaTay
1 Replies
Login or Register to Ask a Question