for i in `cat file` do


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users for i in `cat file` do
# 8  
Old 08-30-2011
using SED:delete multiple lines from LOG file.

Can you please help me reg below issue???

All errors are included inside ‘IGNORE_ERROR.txt'
For.e.g End user will just put all errors inside IGNORE_ERROR.txt' file which they don't want...
ERROR1
ERROR2
ERROR3


Now script should search ERROR1,ERROR2,ERROR3 inside LOG.txt and delete all these lines. Using below script only lines which contain ERROR3 is deleting from LOG.txt
FILE=/home/spm/ptc/scripts/IGNORE_ERROR.txt

##Script-

UNIQUE='-={GR}=-'
#
if [ -z "$FILE" ]; then
exit;
fi;
#
for LINE in `sed "s/ /$UNIQUE/g" $FILE`; do
LINE=`echo $LINE | sed "s/$UNIQUE/ /g"`
echo $LINE >>
sed -e "/"$LINE"/d" /home/spm/ptc/scripts/LOG.txt > /home/spm/ptc/scripts /"RequiredERROR-$SERVER_NAME-`date '+%d-%m-%Y'`.log"
done
# 9  
Old 08-30-2011
dont hijack others thread.. anyway below the code
Code:
$ xargs < IGNORE_ERROR.txt|sed 's, ,|,g;s,^,egrep -v \",g;s,$,\" inputfile,g'|sh

# 10  
Old 08-30-2011
Quote:
Originally Posted by Corona688
That's not even how you're supposed to do this in bash. It's wasteful and dangerous -- a file too long might throw an error, or just be silently truncated. Where did you learn this?
  • Actually, there is nothing that states that's not the way it is suppose to be done. If it works, do it. I agree the potential exists for this to be "wasteful" ... dangerous?, maybe... I've been using this syntax since 1979 with no problems. Maybe I've just been lucky.
  • From the standard Bourne Shell manual... There are no caveat's or restrictions listed in the manual.
I'm in Perth at the moment and won't get back to Adelaide until the end of September, but I think I have an actual example from a Unix Primer (circa 1990) identical to the original one presented... I'll get back to you in October (if I remember)...

Quote:
Originally Posted by The Manual
Command substitution. The standard output from a command enclosed in a pair of grave accents (``) may be used as part or all of a word; trailing newlines are removed.
Obviously limitations exist when using grave accents... the user should be aware of them or suffer the consequences.

Last edited by wabard; 08-30-2011 at 09:40 AM.. Reason: Man, I gotta learn to type....
# 11  
Old 08-30-2011
Quote:
Originally Posted by wabard
dangerous?, maybe... I've been using this syntax since 1979 with no problems. Maybe I've just been lucky.
Either that, or had the intuitive sense to know when using it is a bad idea.

I've answered several threads on this forum about mysterious problems with the "for x in `cat foo`" design where data had been mysteriously lost or ignored. They hit the limit, of course -- the limit's pretty small on some systems.
Quote:
Obviously limitations exist when using grave accents... the user should be aware of them or suffer the consequences.
Agreed. Unfortunately, they can get away with it for quite a long time until the habit becomes ingrained. Most people who use it don't seem to understand the implications, namely, the backticks have to finish first -- they seem to think of them like pipes. I saw a poster suggest using it to process data already known to be a 40-gig flatfile...

When nothing is known about the size of the file, `cat foo` should be discouraged, I feel. Even for small files, I see little reason beyond habit to use it...

Last edited by Corona688; 08-30-2011 at 12:53 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh cat file output into a file on local computer

Hello, I'm on a remote computer by SSH. How can I get the output of "cat file" into a file on the local computer? I cannot use scp, because it's blocked. something like: ssh root@remote_maschine "cat /file" > /locale_machine/file :rolleyes: (2 Replies)
Discussion started by: borsti007
2 Replies

2. Shell Programming and Scripting

perl and file and cat

Hi All i need a little script that can open a file , read it and then spit out some information from it from the shell i would do cat /var/log/Xorg.0.log | grep pixel | sed 's/: 330.*//' | how can i do this nicley in perl thanks Adam (3 Replies)
Discussion started by: ab52
3 Replies

3. Shell Programming and Scripting

Cat file

how to cat a file by ignoring first line and last line (1 Reply)
Discussion started by: thelakbe
1 Replies

4. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

5. Shell Programming and Scripting

cat a file on webpage

Hi, Is there a way to cat a file on Webpage? . Thanks in advance (3 Replies)
Discussion started by: rider29
3 Replies

6. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

7. UNIX for Dummies Questions & Answers

How to cat file

I want to cat a file with only show the line contain '/bin/bash' but don't show the line contain 'load' (don't show if the line contain 'load' and '/bin/bash' together), how to type in the command? thk a lot! (2 Replies)
Discussion started by: zp523444
2 Replies

8. UNIX for Dummies Questions & Answers

Easiest way to cat out first 100 lines of a file into a different file?

Not sure how to do this exactly.. just want to take the first 100 lines of a file and cat it out into a second file. I know I can do a more on a file and > it into a different file, but how can I make it so only the first 100 lines get moved over? (1 Reply)
Discussion started by: LordJezo
1 Replies

9. Shell Programming and Scripting

cat file problem

Hi, I wnat to read a fiel line by line and store each line in a variabel, so I made a for loop: for i in `cat file` ; do #do sth. done; The problem is, that in the file, there are lines with only asterisks like this... (3 Replies)
Discussion started by: bensky
3 Replies
Login or Register to Ask a Question