Reading specific lines from a file using index or keywords


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reading specific lines from a file using index or keywords
# 8  
Old 04-17-2012
Quote:
Originally Posted by Scrutinizer
Make sure there are no spaces after EOF and that it is at the beginning of the line..
Nope, I cannot see the output.

Code:
read frommail tomail ccmail bccmail << EOF
$(awk '{gsub(/^\n|\n$/,x,$2); gsub(ORS,",",$2); A[$1]=$2} END{print A["FROM"] OFS A["TO"] OFS A["CC"] OFS A["BCC"]}' RS=\[ FS=\] emaillist.lst)
EOF
echo "$tomail"
echo "$frommail"
echo "$ccmail"
echo "$bccmail"

this is the script.

Code:
[FROM]
from@mail.com
[TO]
to1@mail.com
to2@mail.com
[CC]
cc@mail.com
cc1@mail.com
[BCC]
bcc@mail.com

this is the file.

Any suggestion????

Thanks.
# 9  
Old 04-17-2012
1. Try it with sh (should be POSIX) instead of ksh

2. See if this works in ksh:
Code:
awk '{gsub(/^\n|\n$/,x,$2); gsub(ORS,",",$2); A[$1]=$2} END{print A["FROM"] OFS A["TO"] OFS A["CC"] OFS A["BCC"]}' RS=\[ FS=\] emaillist.lst |
read frommail tomail ccmail bcc mail
echo "$tomail"
echo "$frommail"
echo "$ccmail"
echo "$bccmail"

3. Do you have /usr/dt/bin/dtksh ? Try that instead of standard ksh..
This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 04-18-2012
@Kyaw Lwin Phyo, could you post which option you ended up using?
# 11  
Old 04-18-2012
Hi Scrutinizer,
I cannot use any of these options yet.
I tried with ksh with ur script, only the empty lines showing up.
And i do not have other shell that u mentioned.
Can u explain me a bit about what is it doing?
And when i logged in using putty, the opening line signs are showing with #, not $ sign.
And HP UX is 11.00. Any suggestions???

Thanks.
Kyaw Lwin Phyo.
# 12  
Old 04-19-2012
What does running only the awk:
Code:
awk '{gsub(/^\n|\n$/,x,$2); gsub(ORS,",",$2); A[$1]=$2} END{print A["FROM"] OFS A["TO"] OFS A["CC"] OFS A["BCC"]}' RS=\[ FS=\] emaillist.lst

give you any output?

--
Wow 11.00 that is 15 years ago BTW.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Copy Lines between Keywords & paste them to another file

hi, I have Multiple files with the following data : File1 100414 DR1 END XXXXX Test1 Test2 Test3 Test4 Test5 Test6 END 100514 DR2 END XXXXX Test7 Test8 Test9 Test10 Test11 Test12 END 100614 DR3 (5 Replies)
Discussion started by: newageBATMAN
5 Replies

2. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

3. Shell Programming and Scripting

Extract lines from file using keywords using script

Hi I need some lines of text from input file using keywords. Inputfile IP IS 10.238.52.65 pun-ras-bng-mhs-01#context bsnl.in Card Status : 1:0, 2:1, 3:1, 4:1, 5:0, 6:0, 7:0, 8:0, 9:1, 10:0, 11:0, 12:0, 13:0, 14:1, Max Circuits: 1: 0, 2: 32768, ... (5 Replies)
Discussion started by: surender reddy
5 Replies

4. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

5. UNIX for Dummies Questions & Answers

Reading a specific line from a file

Hi All, I am having 100 lines a text file say a.txt. I want read the 'nth' line from that file inside a script. Kindly tell us how to that. (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

6. UNIX and Linux Applications

Reading a file for specific words

Hi I have a script where the user calls it with arguments like so: ./import.sh -s DNSNAME -d DBNAME I want to check that the database entered is valid by going through a passwd.ds file and checking if the database exists there. If it doesn't, the I need to send a message to my log... (4 Replies)
Discussion started by: ladyAnne
4 Replies

7. Shell Programming and Scripting

awk: reading into an array and then print the value corresponding to index

I am beginner in awk awk 'BEGIN{for(i=1;(getline<"opnoise")>0;i++) arr=$1}{print arr}' In the above script, opnoise is a file, I am reading it into an array and then printing the value corresponding to index 20. Well this is not my real objective, but I have posted this example to describe... (19 Replies)
Discussion started by: akshaykr2
19 Replies

8. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

9. UNIX for Dummies Questions & Answers

Reading specific part of file

I have a requirement to go to particular line in the file and from there read the contents till it meets a particular criteria. For eg if the contents of the file is like 81 abcd ------------------- Line 1 82 cdfe ------------------- Line 2 83 dfj ------------------- Line 3 84 df... (5 Replies)
Discussion started by: guptan
5 Replies

10. Shell Programming and Scripting

reading specific line from file

Hi all... I not a expert unix script programmer, Kindly adjust. My requirement is that, i have a file which contains the about 10 lines - say 1 2 3 ... 8 war of the worlds: => text in this line 9 9000,80,78,77,334,445 => this line contains some numbers separted by commas 10 ... (10 Replies)
Discussion started by: cool_boss2121
10 Replies
Login or Register to Ask a Question