File lines starts with # not processed or exclude that lines
I have requirement in my every files starting lines have # needs to be not processing or exclude the that lines.
I have written a code like below, but now working as expected getting ERROR" line 60: [egrep: command not found"
Code:
1 #!/bin/sh
2 echo ======= LogManageri start ==========
3
4 #This directory is getting the raw data from remote server
5 Raw_data=/opt/ftplogs
6
7 # This directory is ready for process the data
8 Processing_dir=/opt/processing_dir
9
10 # This directory is prcoessed files and taking backup
11 Processed_dir=/opt/processed_dir
12
13 # This directory spliting the files like access and error logs
14 split_dir=/opt/split_dir
15
16 # Copying Raw data to Processing directory
17 echo starting copying files from $Raw_Data to $Processing_dir
18 cp -p $Raw_data/*.gz $Processing_dir/
19 echo done copying raw files.
20
21 # Decompress .gz files from $Process_dir
22 echo starting unziping files in $Process_dir
23 gunzip $Processing_dir/*.gz
24 echo done unziping files in $Process_dir
25 #path=Processing_dir/*.log
26 #name=$(basename "$Processing_dir/" .log)
27 #echo $name
28
29 # This for loops gives year,month and day from file name
30
31 for file in $Processing_dir/*.log
32 do
33 name=$(basename "$file" .log)
34 echo this $name
35 year=${name:9:4}
36 echo $year
37 month=${name:13:2}
38 echo $month
39 day=${name:15:2}
40 echo $day
41
42 # This while loop reading the file each and every line and spliting the Respective $cname and $code
43 echo start reading files
44 while read -r line
45 do
46 # cname is reading every line from all files
47
48 cname=$(echo ${line} | awk '{split($11,c,"/"); print c[3]}')
49
50 echo $cname
51
52 # scode is reading every line from all files
53
54 scode=$(echo ${line} | awk -F"[ ]" '{print $13}')
55
56 echo $scode
57
58 [[ ! -d "$split_dir/$cname/$year/$month/$day" ]] && mkdir -p "$split_dir/$cname/$year/$month/$day"
59
60 if [egrep -v '^(#|$)' $file]
61 then
62 echo ${line} >> $split_dir/$cname/$month/$day/_line_started_with#.log
63 elif [ ${scode}-le399 ]
64
65 then
66
67 echo ${line} >> $split_dir/$cname/$year/$month/$day/${name}_${cname}_access.log
68
69 else
70 # [[ ( "${scode}"-ge"400" )]]
71
72 echo ${line} >> $split_dir/$cname/$year/$month/$day/${name}_${cname}_error.log
73
74 fi
75
76 done < $file
77
78 done
Please suggest me how can i over come this.
Last edited by Don Cragun; 06-20-2014 at 05:26 AM..
Reason: Add CODE tags.
I have a log file that I am processing. This contains messages from and to a server (requests and responses).
The responses to requests may not be in order i.e. we can have a response to a request after several requests are sent, and in some error cases there may not be any response message.
... (2 Replies)
I use while do - done loop in my shell script. It is working as per my expectations.
But I do not want to process all the lines. I am finding it difficult to exclude certain lines.
1) I do not want to process blank lines as well as lines those start with a space " "
2) I do not want to... (2 Replies)
How can I delete those lines that starts with a certain letter?
abc def ghi
xyz abc def
ace gik moq
abe imq gxm
I want to delete the line that starts with "x". Thanks! (4 Replies)
hiiiii
$ grep ^"#" $file
Will give the lines , which starts with # .And I wanna get the lines which are not starting with #.
How to implement that.
Thanking you
Krish:b: (10 Replies)
Hi Guys,
I have an awk script that would search the input file for line that starts with a number 3 and copies into a new text file.
I want to extend this script to find the lines that either starts with 3 or a or b and copy all those lines into the new file.
Here is what I have so far:... (1 Reply)
Hi, I have one file, I need to check if file exist or not and then remove the lines which starts with ?
My file1.out data is some thing
abcabcppp
xyzxyzpqr
?????????
?????????
Output should be in test.out
abcabcppp
xyzxyzpqr
I am getting the output as below but the File does not exist... (4 Replies)
/bin/sed -n ';4757335,$ p' | wc -l
/bin/sed -n ';4757335,$ p' | egrep "Failed" | egrep -c "PM late arrrival"
how can i combine the above two sed commands into one? i want to count the number of lines between the specified line number and the end of the file. AND and i want to count how many... (5 Replies)
I have a file like below
#Fields section bald
1234 2345 456 222
abcs dddd dddd ssss
mmmm mmm mmm
i need do not process a files stating with #
I was written code below
while read -r line
do
if
then
echo ${line} >>
elif
then
... (3 Replies)
Hi
I have a txt file and I would like to use egrep without using -v option to exclude the lines which matches with multiple Strings.
Let's say I have some text in the txt file. The command should not fetch lines if they have strings something like
CAT MAT DAT
The command should fetch me... (4 Replies)
Discussion started by: Sathwik
4 Replies
LEARN ABOUT DEBIAN
xcalev
XCALEV(1) General Commands Manual XCALEV(1)NAME
xcalev - load xcal calendar files with regular dates
SYNTAX
xcalev [ -r ][ -x ][ -f file ][ -d dir ][ year ]
DESCRIPTION
Xcalev is used to preload the calendar files for the xcal program with regular events in your life. It reads lines from a file (usually
called regular stored in your Calendar directory. Each line in the file contains three fields separated by spaces or tabs, these are: a
month name, a day in the month and some text. For example:
December 25 Christmas
Dec 31 New Year's Eve
The order of the month and the day are optional, the program deduces the day by looking whether the string contains an initial numeric
character or not. The year defaults to the current year unless the program is given a year number as an argument. This year cannot be
abbreviated to two digits because xcal
deals with years from year zero. There's a rough validity check on this.
The string from the data line is inserted in the appropriate file and will appear in your xcal date strip. Nothing will happen if the
string already exists in the file for that day. This means that it's safe to run xcalev at any time, only the strings that have altered in
the regular file will be updated.
To help with entering the same event for a number of days in one month, you can give a day range with a hyphen
Jan 16-21 Usenix SF
If you supply the -r option, xcalev will delete all the matching strings that it finds in the appropriate daily file. So, if you want to
make radical changes to the regular file, you should run xcalev with the -r option to remove all the current entries from one year, edit
the regular file and run xcalev to reload things.
OPTIONS
The -r option makes xcalev delete rather than append entries.
The -x option makes xcalev operate with Calendar files that are compatible with the xcalendar program.
The -f switch is followed by a filename gives an alternative name for the regular file. If the filename does not start with a slash or a
dot, then the name of your Calendar directory will be prepended to it.
The -d switch is followed by a directory name and specifies an alterative location for your Calendar directory. Your home directory is
prepended if the name doesn't start with a slash or a dot.
FILES
$HOME/Calendar/*
xc<dd><Mon><Year> A data file is day, Month in three letter format and the year.
xy<Year> A year directory.
xw<Day> A data file for the weekly code, one per day.
SEE ALSO xcal(1), xcalpr(1), xcal_cal(1)AUTHOR
Copyright 1993 by Peter Collinson, Hillside Systems All rights reserved.
X Version 11 R5 October 1993 XCALEV(1)