Results 1 to 10 of 11
my file has the following content:
name email
=== ====
jim jim@hotmail.com
susan susan@hotmail.com
....
name email
=== ====
ethan ethan@hotmail.com
stephen stephen@hotmail.com
...
the output should be:
jim jim@hotmail.com
...
- 03-20-2007 #1Just Joined!
- Join Date
- Mar 2007
- Posts
- 5
processing file..please help!!
my file has the following content:
name email
=== ====
jim jim@hotmail.com
susan susan@hotmail.com
....
name email
=== ====
ethan ethan@hotmail.com
stephen stephen@hotmail.com
...
the output should be:
jim jim@hotmail.com
susan susan@hotmail.com
....
ethan ethan@hotmail.com
stephen stephen@hotmail.com
any idea??
thanks
- 03-20-2007 #2Just Joined!
- Join Date
- Feb 2005
- Location
- India
- Posts
- 24
Hi,
If u already know what you wanna skip in ur parsing, I don't see what the problem is. U cud:
1] write a simple routing to read words (read one character at a time till u encouter a white space).
2] Check if the word is in the Avoid list.
3] if not forward it to output (whether ur writing it to another file or displaying it on screen).
Also, if ur allowed to change the format of input, you can have some sort of indicator at the start of lines that you wanna avoid, like if your file can look something like
#name email
#==== ====
jim jim@hotmail.com
susan susan@hotmail.com
then it becomes even easier... whenever u encouter a '#' just ignore till '\n'.
I know I'm asking you to hardcode a lot of things... so if someone has a more generic soln, I'm eagerly waiting for it.
- 03-20-2007 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
you just want to get all the lines with email addresses right?
eg
grep "@" file
- 03-20-2007 #4Just Joined!
- Join Date
- Mar 2007
- Posts
- 5
..the lines after:
name email
=== ====
and the above lines occur n time
(
- 03-20-2007 #5As ghostdog74 suggested u can do that or try this script out:you just want to get all the lines with email addresses right?
eg
grep "@" file
You can simplify multiple IF conditions thr...Code:#!/bin/bash STR1="name email" STR2="==== =====" FILE="./addr.txt" FD=6 exec $FD<$FILE while read -u $FD LINE do if [ "$LINE" != "$STR1" ] then if [ "$LINE" != "$STR2" ] then echo $LINE; fi fi done exec $FD<&-
---------------------------------
Registered Linux User #440311
HI2ARUN _AT_ GMAIL _DOT_ COM
---------------------------------
- 03-20-2007 #6Just Joined!
- Join Date
- Mar 2007
- Posts
- 5
cyberinstru,
I get the following error on running your script:
./s.sh: line 8: exec: 6: not found
#!/bin/bash
STR1="name email"
STR2="==== ====="
FILE="./addr.txt"
FD=6 # could u please explain me this line?????
exec $FD<$FILE # at this line!!!!!!!!!!!!
while read -u $FD LINE
do
if [ "$LINE" != "$STR1" ]
then
if [ "$LINE" != "$STR2" ]
then
echo $LINE;
fi
fi
done
exec $FD<&-
- 03-21-2007 #7FD ... any file descriptor other than 0,1 and 2FD=6 # could u please explain me this line?????
This line shud open the file $FILE (addr.txt - whr the email IDs and names are stored).Code:exec $FD<$FILE # at this line!!!!!!!!!!!!
You can try this one by doingat the command prompt, then execute the script. It shud work.Code:exec 6<(filename)
---------------------------------
Registered Linux User #440311
HI2ARUN _AT_ GMAIL _DOT_ COM
---------------------------------
- 03-21-2007 #8Just Joined!
- Join Date
- Mar 2007
- Posts
- 5
.. I get the error:
./s.sh: line 8: exec: 6: not found
((
- 03-21-2007 #9Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:awk ' $0 !~ /name email/ && $0 !~ /=== ====/ { print }' file
- 03-21-2007 #10Just Joined!
- Join Date
- Mar 2007
- Posts
- 5
ghostdog74,
I notice that the records ends with ^F (dec 06) , then new line.
The question is how to tell awk to skip if $0 matches that character ^F??
Thanks


Reply With Quote