Sponsored Content
Top Forums Shell Programming and Scripting File lines starts with # not processed or exclude that lines Post 302906473 by Chenchireddy on Friday 20th of June 2014 02:14:42 AM
Old 06-20-2014
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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting processed lines

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)
Discussion started by: BootComp
2 Replies

2. Shell Programming and Scripting

exclude lines in a loop

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)
Discussion started by: shantanuo
2 Replies

3. Shell Programming and Scripting

Delete lines that starts with a certain letter

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)
Discussion started by: kingpeejay
4 Replies

4. UNIX for Dummies Questions & Answers

Display lines not starts with #

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)
Discussion started by: krishnampkkm
10 Replies

5. Shell Programming and Scripting

how to delete lines from a file which starts with a specific pattern

I need to delete those lines from a file, which starts with 45. How to do it? (3 Replies)
Discussion started by: mady135
3 Replies

6. Shell Programming and Scripting

How to copy lines that starts with either 3 or 4 into new file?

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)
Discussion started by: Amith821
1 Replies

7. Shell Programming and Scripting

Execution problem ---to remove the lines which starts with one type of character

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)
Discussion started by: Ramyajiguru1
4 Replies

8. Shell Programming and Scripting

Running sed and counting number of lines processed

/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)
Discussion started by: SkySmart
5 Replies

9. Shell Programming and Scripting

File lines starts with # not processed or exclude that lines from processing

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)
Discussion started by: Chenchireddy
3 Replies

10. Shell Programming and Scripting

Exclude lines in a file with matches with multiple Strings using egrep

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
GREP(1) 						      General Commands Manual							   GREP(1)

NAME
grep - search a file for a pattern SYNOPSIS
grep [ option ... ] pattern [ file ... ] DESCRIPTION
Grep searches the input files (standard input default) for lines (with newlines excluded) that match the pattern, a regular expression as defined in regexp(6). Normally, each line matching the pattern is `selected', and each selected line is copied to the standard output. The options are -c Print only a count of matching lines. -h Do not print file name tags (headers) with output lines. -i Ignore alphabetic case distinctions. The implementation folds into lower case all letters in the pattern and input before interpre- tation. Matched lines are printed in their original form. -l (ell) Print the names of files with selected lines; don't print the lines. -L Print the names of files with no selected lines; the converse of -l. -n Mark each printed line with its line number counted in its file. -s Produce no output, but return status. -v Reverse: print lines that do not match the pattern. Output lines are tagged by file name when there is more than one input file. (To force this tagging, include /dev/null as a file name argument.) Care should be taken when using the shell metacharacters $*[^|()= and newline in pattern; it is safest to enclose the entire expression in single quotes '...'. SOURCE
/sys/src/cmd/grep.c SEE ALSO
ed(1), awk(1), sed(1), sam(1), regexp(6) DIAGNOSTICS
Exit status is null if any lines are selected, or non-null when no lines are selected or an error occurs. GREP(1)
All times are GMT -4. The time now is 04:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy