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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File lines starts with # not processed or exclude that lines from processing
# 1  
Old 06-20-2014
File lines starts with # not processed or exclude that lines from processing

I have a file like below
Code:
#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

Code:
while read -r line
 do
 
          if [ egrep -v '^#'  $file]
          then
         echo ${line} >>
         elif [ $scode -le 399 ]
          then
          echo ${line} >>access.log
          else
         echo ${line}>>error.log
done > $file

it processing but not expectings
and also tried below like
Code:
           while read -r line
 do
 
          if [ egrep -v '^#'  $file]
          then
         echo ${line} >>
         elif [ $scode -le 399 ]
          then
          echo ${line} >>access.log
          else
         echo ${line}>>error.log
done > `egrep -v '^#'  $file`

it is processing but not going to specific file which i am expecting to access and error.logs

Please correct me where should i correct my script.

both are not working as expected

Last edited by Scrutinizer; 06-20-2014 at 08:51 AM.. Reason: CODE Tags
# 2  
Old 06-20-2014
These 2 Users Gave Thanks to CarloM For This Post:
# 3  
Old 06-20-2014
Thanks for update

where is missing the space
# 4  
Old 06-20-2014
Hi egrep works on an entire file, that is not what you are looking for. You could try this:
Code:
while read -r line
do
  case $line in 
    (\#*) continue
  esac
  printf "%s\n" "$line"
  .....
done < yourfile

Where do you set scode ?

Last edited by Scrutinizer; 06-20-2014 at 10:48 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

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: 1 #!/bin/sh 2 echo ======= LogManageri start ========== 3 4 #This directory is... (1 Reply)
Discussion started by: Chenchireddy
1 Replies

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question